Skip to content

Commit e8f1532

Browse files
atinuxclarkdo
authored andcommitted
feat(webpack): allow function entries for build.transpile (nuxt#6120)
1 parent 5401a51 commit e8f1532

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

packages/webpack/src/config/base.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ export default class WebpackBaseConfig {
3838
isDev: this.dev,
3939
isServer: this.isServer,
4040
isClient: !this.isServer,
41-
isModern: Boolean(this.isModern)
41+
isModern: Boolean(this.isModern),
42+
isLegacy: Boolean(!this.isModern)
4243
}
4344
}
4445

@@ -57,10 +58,13 @@ export default class WebpackBaseConfig {
5758
normalizeTranspile () {
5859
// include SFCs in node_modules
5960
const items = [/\.vue\.js/i]
60-
for (const pattern of this.buildContext.buildOptions.transpile) {
61+
for (let pattern of this.buildContext.buildOptions.transpile) {
62+
if (typeof pattern === 'function') {
63+
pattern = pattern(this.nuxtEnv)
64+
}
6165
if (pattern instanceof RegExp) {
6266
items.push(pattern)
63-
} else {
67+
} else if (typeof pattern === 'string') {
6468
const posixModule = pattern.replace(/\\/g, '/')
6569
items.push(new RegExp(escapeRegExp(path.normalize(posixModule))))
6670
}

packages/webpack/src/config/server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@ export default class WebpackServerConfig extends WebpackBaseConfig {
2020
const whitelist = [
2121
/\.(?!js(x|on)?$)/i
2222
]
23-
for (const pattern of this.buildContext.buildOptions.transpile) {
23+
for (let pattern of this.buildContext.buildOptions.transpile) {
24+
if (typeof pattern === 'function') {
25+
pattern = pattern(this.nuxtEnv)
26+
}
2427
if (pattern instanceof RegExp) {
2528
whitelist.push(pattern)
26-
} else {
29+
} else if (typeof pattern === 'string') {
2730
const posixModule = pattern.replace(/\\/g, '/')
2831
whitelist.push(new RegExp(escapeRegExp(posixModule)))
2932
}

test/unit/basic.dev.test.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ describe('basic dev', () => {
3030
'@scoped/packageA',
3131
'@scoped\\packageB',
3232
'vue.test.js',
33-
/vue-test/
33+
/vue-test/,
34+
({ isModern }) => isModern ? 'modern-test' : 'normal-test'
3435
],
3536
loaders: {
3637
cssModules: {
@@ -77,6 +78,7 @@ describe('basic dev', () => {
7778
expect(transpile(path.normalize('node_modules/test.vue.js'))).toBe(true)
7879
expect(transpile(path.normalize('node_modules/@scoped/packageA/src/index.js'))).toBe(true)
7980
expect(transpile(path.normalize('node_modules/@scoped/packageB/src/index.js'))).toBe(true)
81+
expect(transpile(path.normalize('node_modules/normal-test'))).toBe(true)
8082
})
8183

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

0 commit comments

Comments
 (0)