Skip to content

Commit

Permalink
feat: 支持wxs
Browse files Browse the repository at this point in the history
  • Loading branch information
ximing committed Jul 8, 2019
1 parent 9ec5359 commit e10937d
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
6 changes: 5 additions & 1 deletion src/asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,17 @@ module.exports = class Asset {
get contents() {
if (!this.__content) {
try {
if (/\.(ts|tsx|js|jsx|wxml|wxss|css|less|scss|text|txt|json)$/.test(this.name)) {
if (
/\.(ts|tsx|js|jsx|wxml|wxss|css|less|scss|text|txt|json|wxs)$/.test(this.name)
) {
this.__content = fs.readFileSync(this.filePath, 'utf-8');
} else {
this.__content = fs.readFileSync(this.filePath);
}
this.__stats = fs.statSync(this.filePath);
} catch (e) {
console.log('读取文件失败', this.filePath);
console.error(e);
this.__content = null;
}
}
Expand Down
6 changes: 2 additions & 4 deletions src/plugin/handleJSDep.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module.exports = class HandleJSDep {
mpb.hooks.beforeEmitFile.tapPromise('HandleJSDep', async (asset) => {
const deps = [];
try {
if (/\.js$/.test(asset.outputFilePath) && asset.contents) {
if (/\.(js|wxs)$/.test(asset.outputFilePath) && asset.contents) {
const code = asset.contents;
const ast = babylon.parse(code, { sourceType: 'module' });
babelTraverse(ast, {
Expand Down Expand Up @@ -80,9 +80,7 @@ module.exports = class HandleJSDep {
libOutputPath
);
if (node.arguments[0].value[0] !== '.') {
node.arguments[0].value = `./${
node.arguments[0].value
}`;
node.arguments[0].value = `./${node.arguments[0].value}`;
}
deps.push({
libPath,
Expand Down
2 changes: 2 additions & 0 deletions src/plugin/handleWXMLDep.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = class HandleWXMLDep {
deps.push(attribs.src);
} else if (name === 'include' && attribs.src) {
deps.push(attribs.src);
} else if (name === 'wxs' && attribs.src) {
deps.push(attribs.src);
}
},
onerror(error) {
Expand Down
2 changes: 1 addition & 1 deletion src/watching.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = class Watching {
const asset = this.mpb.assetManager.getAsset(path);
if (asset) {
if (type === 'change') {
console.log('[watching-add-asset]',path)
console.log('[watching-add-asset]', path);
await this.mpb.assetManager.addAsset(path, asset.outputFilePath, asset.meta);
} else if (type === 'unlink') {
await this.mpb.assetManager.delAsset(asset);
Expand Down

0 comments on commit e10937d

Please sign in to comment.