Skip to content

Commit

Permalink
fix(webpack-runner): 默认针对 @tarojs/components 进行编译处理
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Jan 28, 2019
1 parent f46cc6b commit 68d7208
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions packages/taro-webpack-runner/src/util/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ const getModule = ({
module,
plugins
}) => {

const postcssOption: PostcssOption = module.postcss || {}

const styleLoader = getStyleLoader([{ sourceMap: enableSourceMap }, styleLoaderOption])
Expand Down Expand Up @@ -333,27 +333,22 @@ const getModule = ({
}

const isNodemodule = filename => /\bnode_modules\b/.test(filename)
let esnextModuleRegs = [/@tarojs\/components/]
if (Array.isArray(esnextModules) && esnextModules.length) {
/* cnpm 安装的模块名前带下划线 `_` */
const esnextModuleRegs = [
/@tarojs\/components/,
...esnextModules.map(v => new RegExp(`node_modules[\\\\/]_?${v}`))
]
/**
* isEsnextModule
*
* 使用正则匹配判断是否是es模块
* 规则参考:https://github.com/webpack/webpack/blob/master/lib/RuleSet.js#L413
*/
const isEsnextModule = filename => esnextModuleRegs.some(reg => reg.test(filename))
const notTaroModules = filename => isEsnextModule(filename) ? false : isNodemodule(filename)
/* 通过taro处理 */
rule.jsx.exclude = [notTaroModules]
rule.postcss.exclude = [notTaroModules]
} else {
rule.jsx.exclude = [isNodemodule]
rule.postcss.exclude = [isNodemodule]
esnextModuleRegs = esnextModuleRegs.concat([...esnextModules.map(v => new RegExp(`node_modules[\\\\/]_?${v}`))])
}
/**
* isEsnextModule
*
* 使用正则匹配判断是否是es模块
* 规则参考:https://github.com/webpack/webpack/blob/master/lib/RuleSet.js#L413
*/
const isEsnextModule = filename => esnextModuleRegs.some(reg => reg.test(filename))
const notTaroModules = filename => isEsnextModule(filename) ? false : isNodemodule(filename)
/* 通过taro处理 */
rule.jsx.exclude = [notTaroModules]
rule.postcss.exclude = [notTaroModules]
return { rule }
}

Expand Down

0 comments on commit 68d7208

Please sign in to comment.