diff --git a/lib/builder/webpack/base.js b/lib/builder/webpack/base.js index 04d4713645..3847ff8ba7 100644 --- a/lib/builder/webpack/base.js +++ b/lib/builder/webpack/base.js @@ -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() diff --git a/lib/common/nuxt.config.js b/lib/common/nuxt.config.js index a2da29d2d0..50e08ef430 100644 --- a/lib/common/nuxt.config.js +++ b/lib/common/nuxt.config.js @@ -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: [],