Skip to content

Commit

Permalink
feat: 增加配置项 DACE_BABEL_COMPILE_MODULES ,用来指定哪些依赖包需要通过 babel 编译
Browse files Browse the repository at this point in the history
  • Loading branch information
zhongzhi107 committed Dec 26, 2019
1 parent 33dc01a commit 580b544
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/utils/defaultEnv.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ export default {
// 静态文件长期缓存长度
DACE_LONG_TERM_CACHING_LENGTH: '8',

// node_modules 中需要通过 babel 编译的模块名称列表,用逗号连接
DACE_BABEL_COMPILE_MODULES: '',

// 以 `DACE_PATH_` 开头的变量会转换成绝对路径
// 工程根目录
DACE_PATH_ROOT: '.',
Expand Down
23 changes: 22 additions & 1 deletion src/webpack/config/createConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export default ({
DACE_SERVER_MINIMIZE,
DACE_CLIENT_MINIMIZE,
DACE_POLYFILL,
DACE_BABEL_COMPILE_MODULES,
DACE_PATH_BABEL_RC,
DACE_PATH_ESLINT_RC,
DACE_PATH_POSTCSS_RC,
Expand Down Expand Up @@ -94,6 +95,20 @@ export default ({
};
}

const babelIncludeOptions = DACE_BABEL_COMPILE_MODULES
.split(',')
.map((name) => {
name = name.trim();
if (name === '') {
return null;
}
return path.resolve(`node_modules/${name}`);
})
.concat(path.resolve('src'))
.filter(Boolean);

console.log(babelIncludeOptions);

// 获取 .eslintrc.js 配置
const hasEslintRc = fs.existsSync(DACE_PATH_ESLINT_RC);
const mainEslintOptions = {
Expand Down Expand Up @@ -187,7 +202,13 @@ export default ({
},
{
test: /\.(js|jsx)$/,
exclude: [/node_modules/],
include: babelIncludeOptions,
// exclude: [/node_modules/],
// and: [
// /chalk/
// // '/Users/zhi.zhong/workspace/q/h_pc_ssr/node_modules/chalk/index.js'
// // path.resolve('node_modules/chalk/index.js')
// ],
use: [
{
loader: require.resolve('babel-loader'),
Expand Down

0 comments on commit 580b544

Please sign in to comment.