fix(webpack): prefer main over module field for server config (#5446)

[release]
This commit is contained in:
Xin Du (Clark) 2019-04-02 14:00:32 +01:00 committed by Pooya Parsa
parent 1ae433355e
commit e155ea43d7
2 changed files with 26 additions and 12 deletions

View File

@ -147,6 +147,22 @@ export default class WebpackBaseConfig {
return optimization return optimization
} }
resolve() {
// Prioritize nested node_modules in webpack search path (#2558)
const webpackModulesDir = ['node_modules'].concat(this.buildContext.options.modulesDir)
return {
resolve: {
extensions: ['.wasm', '.mjs', '.js', '.json', '.vue', '.jsx', '.ts', '.tsx'],
alias: this.alias(),
modules: webpackModulesDir
},
resolveLoader: {
modules: webpackModulesDir
}
}
}
minimizer() { minimizer() {
const minimizer = [] const minimizer = []
const { terser, cache } = this.buildContext.buildOptions const { terser, cache } = this.buildContext.buildOptions
@ -414,9 +430,6 @@ export default class WebpackBaseConfig {
} }
config() { config() {
// Prioritize nested node_modules in webpack search path (#2558)
const webpackModulesDir = ['node_modules'].concat(this.buildContext.options.modulesDir)
const config = { const config = {
name: this.name, name: this.name,
mode: this.mode, mode: this.mode,
@ -427,18 +440,11 @@ export default class WebpackBaseConfig {
maxEntrypointSize: 1000 * 1024, maxEntrypointSize: 1000 * 1024,
hints: this.dev ? false : 'warning' hints: this.dev ? false : 'warning'
}, },
resolve: {
extensions: ['.wasm', '.mjs', '.js', '.json', '.vue', '.jsx', '.ts', '.tsx'],
alias: this.alias(),
modules: webpackModulesDir
},
resolveLoader: {
modules: webpackModulesDir
},
module: { module: {
rules: this.rules() rules: this.rules()
}, },
plugins: this.plugins() plugins: this.plugins(),
...this.resolve()
} }
// Clone deep avoid leaking config between Client and Server // Clone deep avoid leaking config between Client and Server

View File

@ -53,6 +53,14 @@ export default class WebpackServerConfig extends WebpackBaseConfig {
} }
} }
resolve() {
const resolveConfig = super.resolve()
resolveConfig.resolve.mainFields = ['main', 'module']
return resolveConfig
}
alias() { alias() {
const aliases = super.alias() const aliases = super.alias()