Record the vue.config.js configuration items I have encountered, and the reasons for using them at the time.
publicPath
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/vue/'
: '/',
}
If your domain name is https://www.iicoom.top , if the path of the generation environment https://www.iicoom.top/ is already occupied by other projects,
https://www.iicoom.top/vue/ This path is accessed, then the above configuration can be achieved.
configureWebpack
remove log
Usually when the project is developed and debugged, there will inevitably be some debugging and some logs will be printed. It may be troublesome to manually remove these logs when the project goes online. With the following configuration, when we use
npm run build
// or
yarn build
After that, the compiled code is deployed to the online environment, and opening the console is refreshing.
module.exports = {
configureWebpack: config => {
// 生产环境取消 console.log
if (process.env.NODE_ENV === 'production') {
config.optimization.minimizer[0].options.terserOptions.compress.warnings = false
config.optimization.minimizer[0].options.terserOptions.compress.drop_console = true
config.optimization.minimizer[0].options.terserOptions.compress.drop_debugger = true
config.optimization.minimizer[0].options.terserOptions.compress.pure_funcs = ['console.log']
}
}
}
resolve
At that time, a rich text editor called summernote was introduced into the project. It depends on bootstrap and jQuery. After installing the dependencies, it still prompts that jquery is not installed, so the following configuration is performed to solve the problem.
const path = require('path');
module.exports = {
// 选项...
configureWebpack: {
resolve: {
alias: {
'jquery': path.resolve(__dirname, './node_modules/jquery/src/jquery'),
'jQuery': path.resolve(__dirname, './node_modules/jquery/src/jquery')
}
}
}
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。