const path = require('path');
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
pages: {
index: {
entry: 'src/main.js'
}
},
productionSourceMap: false,// 生产环境是否要生成 sourceMap
publicPath: './', // 部署应用包时的基本 URL
outputDir: 'dist', // 打包时输出的文件目录
assetsDir: 'assets', // 放置静态文件夹目录
devServer: {
port: 8001, //开发环境运行时的端口
https: false,//是否启用HTTPS协议
open: true, //项目运行成功后是否直接打开浏览器
hot: true,//是否开启热加载
overlay: true, //当出现编译错误或警告时,在浏览器中显示全屏覆盖。
proxy: { //服务器代理
'/api': {
target: "http://39.107.251.252:8001", // 实际跨域请求的API地址
secure: false, // https请求则使用true
ws: true,
changeOrigin: true, // 跨域
// 请求地址重写 http://front-end/api/login ⇒ http://api-url/login
pathRewrite: {
'^/api': '/',
}
}
},// dev环境下,webpack-dev-server 相关配置
lintOnSave: false,//是否在开发环境下每次保存代码时都启用 eslint验证
css: {},// css的处理
//vue-cli内部的webpack配置
chainWebpack(config) {
// it can improve the speed of the first screen, it is recommended to turn on preload
config.plugin('preload').tap(() => [
{
rel: 'preload',
// to ignore runtime.js
// https://github.com/vuejs/vue-cli/blob/dev/packages/@vue/cli-service/lib/config/app.js#L171
fileBlacklist: [/\.map$/, /hot-update\.js$/, /runtime\..*\.js$/],
include: 'initial'
}
])
// when there are many pages, it will cause too many meaningless requests
config.plugins.delete('prefetch')
// set svg-sprite-loader
config.module
.rule('svg')
.exclude.add(resolve('src/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(resolve('src/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
config.module
.rule('markdown')
.test(/\.md$/)
.use('frontmatter-markdown-loader')
.loader('frontmatter-markdown-loader')
.tap(() => {
return {
mode: [require('frontmatter-markdown-loader/mode').VUE_COMPONENT],
vue: {
root: 'markdown-body'
}
}
})
config
.when(process.env.NODE_ENV !== 'development',
config => {
config
.plugin('ScriptExtHtmlWebpackPlugin')
.after('html')
.use('script-ext-html-webpack-plugin', [{
// `runtime` must same as runtimeChunk name. default is `runtime`
inline: /runtime\..*\.js$/
}])
.end()
config
.optimization.splitChunks({
chunks: 'all',
cacheGroups: {
libs: {
name: 'chunk-libs',
test: /[\\/]node_modules[\\/]/,
priority: 10,
chunks: 'initial' // only package third parties that are initially dependent
},
elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/ // in order to adapt to cnpm
},
commons: {
name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules
minChunks: 3, // minimum common number
priority: 5,
reuseExistingChunk: true
}
}
})
// https:// webpack.js.org/configuration/optimization/#optimizationruntimechunk
config.optimization.runtimeChunk('single')
}
)
},
pluginOptions: {}, // 可以用来传递任何第三方插件选项
}
}