mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-17 06:01:34 +00:00
feat(webpack): allow function entries for build.transpile
(#6120)
This commit is contained in:
parent
5401a51862
commit
e8f1532124
@ -38,7 +38,8 @@ export default class WebpackBaseConfig {
|
|||||||
isDev: this.dev,
|
isDev: this.dev,
|
||||||
isServer: this.isServer,
|
isServer: this.isServer,
|
||||||
isClient: !this.isServer,
|
isClient: !this.isServer,
|
||||||
isModern: Boolean(this.isModern)
|
isModern: Boolean(this.isModern),
|
||||||
|
isLegacy: Boolean(!this.isModern)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,10 +58,13 @@ export default class WebpackBaseConfig {
|
|||||||
normalizeTranspile () {
|
normalizeTranspile () {
|
||||||
// include SFCs in node_modules
|
// include SFCs in node_modules
|
||||||
const items = [/\.vue\.js/i]
|
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) {
|
if (pattern instanceof RegExp) {
|
||||||
items.push(pattern)
|
items.push(pattern)
|
||||||
} else {
|
} else if (typeof pattern === 'string') {
|
||||||
const posixModule = pattern.replace(/\\/g, '/')
|
const posixModule = pattern.replace(/\\/g, '/')
|
||||||
items.push(new RegExp(escapeRegExp(path.normalize(posixModule))))
|
items.push(new RegExp(escapeRegExp(path.normalize(posixModule))))
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,13 @@ export default class WebpackServerConfig extends WebpackBaseConfig {
|
|||||||
const whitelist = [
|
const whitelist = [
|
||||||
/\.(?!js(x|on)?$)/i
|
/\.(?!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) {
|
if (pattern instanceof RegExp) {
|
||||||
whitelist.push(pattern)
|
whitelist.push(pattern)
|
||||||
} else {
|
} else if (typeof pattern === 'string') {
|
||||||
const posixModule = pattern.replace(/\\/g, '/')
|
const posixModule = pattern.replace(/\\/g, '/')
|
||||||
whitelist.push(new RegExp(escapeRegExp(posixModule)))
|
whitelist.push(new RegExp(escapeRegExp(posixModule)))
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,8 @@ describe('basic dev', () => {
|
|||||||
'@scoped/packageA',
|
'@scoped/packageA',
|
||||||
'@scoped\\packageB',
|
'@scoped\\packageB',
|
||||||
'vue.test.js',
|
'vue.test.js',
|
||||||
/vue-test/
|
/vue-test/,
|
||||||
|
({ isModern }) => isModern ? 'modern-test' : 'normal-test'
|
||||||
],
|
],
|
||||||
loaders: {
|
loaders: {
|
||||||
cssModules: {
|
cssModules: {
|
||||||
@ -77,6 +78,7 @@ describe('basic dev', () => {
|
|||||||
expect(transpile(path.normalize('node_modules/test.vue.js'))).toBe(true)
|
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/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/@scoped/packageB/src/index.js'))).toBe(true)
|
||||||
|
expect(transpile(path.normalize('node_modules/normal-test'))).toBe(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('Config: build.filenames', () => {
|
test('Config: build.filenames', () => {
|
||||||
|
Loading…
Reference in New Issue
Block a user