盐都地图
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

79 lines
2.5 KiB

const path = require('path') // 引入path模块
// const HtmlWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
function resolve(dir) {
return path.join(__dirname, dir) // path.join(__dirname)设置绝对路径
}
const {
defineConfig
} = require('@vue/cli-service')
module.exports = defineConfig({
lintOnSave: false, // 关闭eslint校验
transpileDependencies: true,
publicPath: '/',
// 将构建好的文件输出到哪里
outputDir: process.env.VUE_APP_OUTPUTDIR,
// 放置生成的静态资源(js、css、img、fonts)的目录
assetsDir: 'static',
// 指定生成的 index.html 的输出路径
indexPath: 'index.html',
// 是否在构建生产包时生成 sourceMap 文件,false将提高构建速度
productionSourceMap: false,
// 是一个函数,允许对内部的 webpack 配置进行更细粒度的修改。
chainWebpack: (config) => {
// 配置别名
config.resolve.alias
.set('@', resolve('src'))
.set('assets', resolve('src/assets'))
.set('components', resolve('src/components'))
.set('views', resolve('src/views'))
config.optimization.minimizer('terser').tap((args) => {
// 去除生产环境console
args[0].terserOptions.compress.drop_console = true
return args
})
},
// 配置 Webpack 相关的配置项
configureWebpack: config => {
// 配置 Webpack 插件
// config.plugins.push(new HtmlWebpackPlugin({
// template: './public/index.html'
// }))
if(process.env.NODE_ENV == 'production'){
config.plugins.push(new BundleAnalyzerPlugin({
analyzerMode: 'server',
analyzerHost: '127.0.0.1',
analyzerPort: 8888, //注意是否有端口冲突
reportFilename: 'report.html',
defaultSizes: 'parsed',
openAnalyzer: true,
generateStatsFile: false,
statsFilename: 'stats.json',
statsOptions: null,
logLevel: 'info'
}))
}
},
// 配置开发服务器
// 本地项目运行时的环境配置
devServer: {
host: 'localhost',
port: 8080, // 端口号
https: false,
open: false, // 配置自动启动浏览器 open: 'Google Chrome'-默认启动谷歌
hot: true, // 热更新
proxy: {
'/api': {
target: 'http://localhost:3000', // 要访问的跨域的域名
ws: true, // 是否启用websockets
changeOrigin: true, // 开启代理:在本地会创建一个虚拟服务端,然后发送请求的数据,并同时接收请求的数据,这样客户端端和服务端进行数据的交互就不会有跨域问题
pathRewrite: {
'^/api': ''
}
}
}
}
})