Skip to content

Commit

Permalink
feat(webpack): allow function entries for build.transpile (#6120)
Browse files Browse the repository at this point in the history
  • Loading branch information
atinux authored and clarkdo committed Aug 3, 2019
1 parent 5401a51 commit e8f1532
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/webpack/src/config/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ export default class WebpackBaseConfig {
isDev: this.dev,
isServer: this.isServer,
isClient: !this.isServer,
isModern: Boolean(this.isModern)
isModern: Boolean(this.isModern),
isLegacy: Boolean(!this.isModern)
}
}

Expand All @@ -57,10 +58,13 @@ export default class WebpackBaseConfig {
normalizeTranspile () {
// include SFCs in node_modules
const items = [/\.vue\.js/i]
for (const pattern of this.buildContext.buildOptions.transpile) {
for (let pattern of this.buildContext.buildOptions.transpile) {
if (typeof pattern === 'function') {
pattern = pattern(this.nuxtEnv)
}
if (pattern instanceof RegExp) {
items.push(pattern)
} else {
} else if (typeof pattern === 'string') {
const posixModule = pattern.replace(/\\/g, '/')
items.push(new RegExp(escapeRegExp(path.normalize(posixModule))))
}
Expand Down
7 changes: 5 additions & 2 deletions packages/webpack/src/config/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ export default class WebpackServerConfig extends WebpackBaseConfig {
const whitelist = [
/\.(?!js(x|on)?$)/i
]
for (const pattern of this.buildContext.buildOptions.transpile) {
for (let pattern of this.buildContext.buildOptions.transpile) {
if (typeof pattern === 'function') {
pattern = pattern(this.nuxtEnv)
}
if (pattern instanceof RegExp) {
whitelist.push(pattern)
} else {
} else if (typeof pattern === 'string') {
const posixModule = pattern.replace(/\\/g, '/')
whitelist.push(new RegExp(escapeRegExp(posixModule)))
}
Expand Down
4 changes: 3 additions & 1 deletion test/unit/basic.dev.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ describe('basic dev', () => {
'@scoped/packageA',
'@scoped\\packageB',
'vue.test.js',
/vue-test/
/vue-test/,
({ isModern }) => isModern ? 'modern-test' : 'normal-test'
],
loaders: {
cssModules: {
Expand Down Expand Up @@ -77,6 +78,7 @@ describe('basic dev', () => {
expect(transpile(path.normalize('node_modules/test.vue.js'))).toBe(true)
expect(transpile(path.normalize('node_modules/@scoped/packageA/src/index.js'))).toBe(true)
expect(transpile(path.normalize('node_modules/@scoped/packageB/src/index.js'))).toBe(true)
expect(transpile(path.normalize('node_modules/normal-test'))).toBe(true)
})

test('Config: build.filenames', () => {
Expand Down

0 comments on commit e8f1532

Please sign in to comment.