fix(webpack): reduce false negatives in nodeExternals (#7462) (#7464)

This commit is contained in:
Johannes Lamberts 2020-06-09 18:40:39 +02:00 committed by GitHub
parent 0acfc78932
commit 846cfee170
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,6 +7,11 @@ import VueSSRServerPlugin from '../plugins/vue/server'
import WebpackBaseConfig from './base'
const nativeFileExtensions = [
'.json',
'.js'
]
export default class WebpackServerConfig extends WebpackBaseConfig {
constructor (...args) {
super(...args)
@ -20,11 +25,23 @@ export default class WebpackServerConfig extends WebpackBaseConfig {
get externalsWhitelist () {
return [
/\.(?!js(x|on)?$)/i,
this.isNonNativeImport.bind(this),
...this.normalizeTranspile()
]
}
/**
* files *not* ending on js|json should be processed by webpack
*
* this might generate false-positives for imports like
* - "someFile.umd" (actually requiring someFile.umd.js)
* - "some.folder" (some.folder being a directory containing a package.json)
*/
isNonNativeImport (modulePath) {
const extname = path.extname(modulePath)
return extname !== '' && !nativeFileExtensions.includes(extname)
}
env () {
return Object.assign(
super.env(),