refactor: simplify build.transpile

This commit is contained in:
Clark Du 2018-05-06 20:48:19 +01:00
parent a888136ac4
commit 13ae634c74
No known key found for this signature in database
GPG Key ID: D0E5986AF78B86D9
2 changed files with 5 additions and 8 deletions

View File

@ -142,14 +142,7 @@ export default class WebpackBaseConfig {
exclude: file => { exclude: file => {
// not exclude files outside node_modules // not exclude files outside node_modules
if (/node_modules/.test(file)) { if (/node_modules/.test(file)) {
let transpile = this.options.build.transpile || [] for (let pkg of 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 // item in transpile can be string or regex object
if (new RegExp(pkg).test(file)) { if (new RegExp(pkg).test(file)) {
return false return false

View File

@ -187,5 +187,9 @@ Options.from = function (_options) {
if (options.dev) { if (options.dev) {
options.build.extractCSS = false options.build.extractCSS = false
} }
// include SFCs in node_modules
options.build.transpile = [/\.vue\.js/].concat(options.build.transpile || [])
return options return options
} }