By default, the development mode and release mode of the Vue project share the same packaged entry file (ie src/main.js
). In order to separate the development process of the project from the release process , we can specify the packaged entry file for each of the two modes, namely:
- The entry file of the development mode is
src/main-dev.js
- The entry file of the release mode is
src/main-prod.js
In the vue.config.js
exported configuration object, add a new configureWebpack
or chainWebpack
node to customize the packaging configuration of webpack.
Here, configureWebpack
and have chainWebpack
the same effect, the only difference is that they modify the webpack configuration in a different way:
chainWebpack
Modify the default webpack configuration through chain programmingconfigureWebpack
Modify the default webpack configuration by operating the object
Through chainWebpack
custom packaging entry
vue.config.js
Add a chainWebpack
node under the root directory of the Vue project , such as:
module.exports = {
chainWebpack: config => {
// 发布模式
config.when(process.env.NODE_ENV === 'production', config => {
config.entry('app').clear().add('./src/main-prod.js')
});
// 开发模式
config.when(process.env.NODE_ENV === 'development', config => {
config.entry('app').clear().add('./src/main-dev.js')
});
}
}