vue打包

1,008 阅读1分钟

vue打包📦

1npm run build

运行命令后,项目文件会多一个dist目录,这个dist就是最终要传到服务器的文件

去掉打包后js的map文件

vue.config.js中配置

1module.exports = {
2    productionSourceMapfalse
3}
打包到指定的文件夹下
1outputDir:'./myDist'
指定根目录

上线用指定的域名根目录访问,测试用/

1publicPath:process.env.NODE_ENV === 'production' ? 'http://www.xx.com' : '/'
设置静态资源路径
1assetsDir: 'assets',
配置webpack,默认隐藏
 1const path =  require('path');
2module.exports = {
3  chainWebpackconfig => {
4    //这里可以增加webpack配置
5    //这里测试,给view目录配置别名 比如@访问src目录
6    resolve.alias.set('_v',path.resolve(__dirname,'src/views'))
7  }
8  //配置webpack   
9  configureWebpack: {
10      //plugin: [],
11    //module: {}
12    }
13    devServer: {
14    //配置代理跨域
15    proxy: {
16      '/api/chat/sendMsg': {
17        target'http://www.xx.com'
18      }
19    }   
20  },
21  //将公共less文件注入到全局
22  pluginOptions: {
23    'style-resources-loader': {
24      preProcessor'less',
25      patterns: [
26        path.resolve(__dirname,'src/assets/styles/variable.less')
27      ]
28        }
29    }
30}