| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- 'use strict'
- const path = require('path')
- const IS_PROD = process.env.NODE_ENV === 'production'
- function resolve (dir) {
- return path.join(__dirname, dir)
- }
- const npmConfigArgv = (process.env.npm_config_argv === undefined) ? null : JSON.parse(process.env.npm_config_argv)
- /*
- console.log('npm config: ', npmConfigArgv)
- const procArgv = process.argv
- console.log('npm config: ', procArgv)
- */
- let buildProdFlag = false
- if (!!npmConfigArgv) {
- npmConfigArgv.original.forEach(cItem => {
- if (cItem === 'build') {
- buildProdFlag = true
- }
- })
- }
- const mvdir = require('mvdir');
- if (IS_PROD && buildProdFlag) {
- mvdir('index_template/index_prod.html', 'public/index.html', { copy: true });
- } else {
- mvdir('index_template/index_dev.html', 'public/index.html', { copy: true });
- }
- module.exports = {
- publicPath: './',
- assetsDir: './',
- /* 开启vue运行时模板编译功能!! */
- runtimeCompiler: true,
- lintOnSave: false,
- productionSourceMap: false,
- devServer: {
- // port: port,
- open: true,
- overlay: {
- warnings: false,
- errors: true
- },
- proxy: {
- '/dev-api': {
- // target: 'http://localhost:6001/gw-admin/',
- target: 'http://192.168.0.166:6001/gw-admin/', //鲁阳的
- changeOrigin: true,
- ws: true,
- // logLevel:'debug',
- pathRewrite: { // 重命名
- '^/dev-api': ''
- },
- onProxyReq: function (proxyReq, req, res, options) {
- if (req.body) {
- const reg = new RegExp('application/json')
- if (reg.test(proxyReq.getHeader('Content-Type'))) {
- const bodyData = JSON.stringify(req.body)
- proxyReq.setHeader('Content-Length', Buffer.byteLength(bodyData))
- proxyReq.write(bodyData)
- }
- }
- }
- }
- }
- },
- /* 指定node_modules目录中需要做babel转译的依赖库 */
- transpileDependencies: [
- 'element-ui', 'vuedraggable',
- ],
- css: {
- loaderOptions: {
- scss: {
- /* 自动引入全局scss文件 */
- prependData: `
- @import "./src/styles/global.scss";
- `
- }
- }
- },
- configureWebpack: (config) => {
- config.devtool = 'source-map'
- config.output.libraryExport = 'default' /* 解决import UMD打包文件时, 组件install方法执行报错的问题!! */
- if (IS_PROD && buildProdFlag) { /* 仅生产环境使用 */
- /* CDN打包,需要修改index.html加入CDN资源 */
- console.log('==========================================')
- config.externals = {
- 'vue': 'Vue',
- 'element-ui': 'ELEMENT',
- //'quill': 'Quill',
- }
- } else {
- // config.externals = {
- // 'vue': 'Vue',
- // 'element-ui': 'ELEMENT',
- // 'axios': 'axios',
- // }
- }
- },
- chainWebpack: config => {
- /* 配置svg图标自动加载 begin */
- 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]'
- })
- /* 配置svg图标自动加载 end */
- },
- }
|