diff --git a/packages/webpack/src/config/base.js b/packages/webpack/src/config/base.js index ad4f8c946e..445bdd507a 100644 --- a/packages/webpack/src/config/base.js +++ b/packages/webpack/src/config/base.js @@ -147,6 +147,22 @@ export default class WebpackBaseConfig { 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() { const minimizer = [] const { terser, cache } = this.buildContext.buildOptions @@ -414,9 +430,6 @@ export default class WebpackBaseConfig { } config() { - // Prioritize nested node_modules in webpack search path (#2558) - const webpackModulesDir = ['node_modules'].concat(this.buildContext.options.modulesDir) - const config = { name: this.name, mode: this.mode, @@ -427,18 +440,11 @@ export default class WebpackBaseConfig { maxEntrypointSize: 1000 * 1024, hints: this.dev ? false : 'warning' }, - resolve: { - extensions: ['.wasm', '.mjs', '.js', '.json', '.vue', '.jsx', '.ts', '.tsx'], - alias: this.alias(), - modules: webpackModulesDir - }, - resolveLoader: { - modules: webpackModulesDir - }, module: { rules: this.rules() }, - plugins: this.plugins() + plugins: this.plugins(), + ...this.resolve() } // Clone deep avoid leaking config between Client and Server diff --git a/packages/webpack/src/config/server.js b/packages/webpack/src/config/server.js index 7cd6718df9..66dd9b8249 100644 --- a/packages/webpack/src/config/server.js +++ b/packages/webpack/src/config/server.js @@ -53,6 +53,14 @@ export default class WebpackServerConfig extends WebpackBaseConfig { } } + resolve() { + const resolveConfig = super.resolve() + + resolveConfig.resolve.mainFields = ['main', 'module'] + + return resolveConfig + } + alias() { const aliases = super.alias()