feat: add build.transpile to transpile npm packages

This commit is contained in:
Clark Du 2018-05-06 19:46:02 +01:00
parent 021ba5a1e2
commit 8b0c2f1a67
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
2 changed files with 21 additions and 7 deletions

View File

@ -40,7 +40,6 @@ export default class WebpackBaseConfig {
]
}
delete options.exclude
return options
}
@ -140,7 +139,25 @@ export default class WebpackBaseConfig {
},
{
test: /\.jsx?$/,
exclude: this.options.build.babel.exclude,
exclude: file => {
// not exclude files outside node_modules
if (/node_modules/.test(file)) {
let transpile = this.options.build.transpile || []
// transpile supports string like 'vue-lib'
if (!Array.isArray(transpile)) {
transpile = [transpile]
}
// include SFCs in node_modules
transpile.push(/\.vue\.js/)
for (let pkg of transpile) {
// item in transpile can be string or regex object
if (new RegExp(pkg).test(file)) {
return false
}
}
return true
}
},
use: perfLoader.pool('js', {
loader: 'babel-loader',
options: this.getBabelOptions()

View File

@ -61,12 +61,9 @@ export default {
},
babel: {
babelrc: false,
cacheDirectory: undefined,
exclude: file => (
/node_modules/.test(file) &&
!/\.vue\.js/.test(file)
)
cacheDirectory: undefined
},
transpile: [], // Name of NPM packages to be transpiled
vueLoader: {},
postcss: {},
templates: [],