Skip to content

Commit c04bbbe

Browse files
committed
fix(build): enable file compiler for all assets
1 parent 90fbfa6 commit c04bbbe

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

packages/mars-build/src/compiler/file/compiler.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,27 +76,38 @@ async function compileJS(content, options) {
7676
return res;
7777
}
7878

79+
function compileDefault(code, options) {
80+
return {
81+
code
82+
};
83+
}
84+
7985
async function compile(file, options) {
8086
const {fileSuffix, target} = options;
8187
const buildConfig = options._config || {};
82-
const cssCompiler = getFileCompiler(compileStyle, buildConfig);
83-
const jsCompiler = getFileCompiler(compileJS, buildConfig);
8488
file.lang = path.extname(file.path).substr(1);
8589

86-
// h5 的没有编译 sfc 中的 style block, assets file 也先不编译保持一致
8790
if (isCSS(file.path)) {
8891
file.type = 'css';
8992
file.path = changeExt(file.path, fileSuffix.css);
93+
const cssCompiler = getFileCompiler(compileStyle, buildConfig);
9094
await cssCompiler(file, options);
9195
}
92-
if (isJS(file.path)) {
96+
else if (isJS(file.path)) {
9397
file.type = 'js';
9498
// TODO: H5 支持 ts 文件编译
9599
if (target !== 'h5') {
96100
file.path = changeExt(file.path, fileSuffix.js);
97101
}
102+
const jsCompiler = getFileCompiler(compileJS, buildConfig);
98103
await jsCompiler(file, options);
99104
}
105+
else {
106+
// for other files, use default compiler
107+
const compiler = getFileCompiler(compileDefault, buildConfig);
108+
await compiler(file, options);
109+
}
110+
100111
return file;
101112
}
102113

0 commit comments

Comments
 (0)