tidy
This commit is contained in:
parent
dc9e4fc700
commit
156a657198
14
index.js
14
index.js
@ -1,21 +1,21 @@
|
||||
const fs = require('fs');
|
||||
|
||||
const readText = filename => new Promise(res => fs.readFile(filename, (err, data) => (err ? res(null) : res(data.toString()))));
|
||||
const read_text = filename => new Promise(res => fs.readFile(filename, (err, data) => (err ? res(null) : res(data.toString()))));
|
||||
|
||||
module.exports = ({ extensions = ['.html', '.svelte'] } = {}) => ({
|
||||
transform(code, id) {
|
||||
const extension = extensions.find(extension => id.endsWith(extension));
|
||||
if (extension) {
|
||||
const baseId = id.slice(0, -extension.length);
|
||||
const jsId = baseId + '.js';
|
||||
const cssId = baseId + '.css';
|
||||
return Promise.all([jsId, cssId].map(readText)).then(([js, css]) => {
|
||||
const base_id = id.slice(0, -extension.length);
|
||||
const js_id = base_id + '.js';
|
||||
const css_id = base_id + '.css';
|
||||
return Promise.all([js_id, css_id].map(read_text)).then(([js, css]) => {
|
||||
if (js) {
|
||||
this.addWatchFile(jsId);
|
||||
this.addWatchFile(js_id);
|
||||
code += `\n<script>\n${js}\n</script>\n`;
|
||||
}
|
||||
if (css) {
|
||||
this.addWatchFile(cssId);
|
||||
this.addWatchFile(css_id);
|
||||
code += `\n<style>\n${css}\n</style>\n`;
|
||||
}
|
||||
return code;
|
||||
|
Loading…
Reference in New Issue
Block a user