# 项目基础配置
# 目录结构
├── build # 构建相关
├── mock # 项目mock 模拟数据
├── plop-templates # 基本模板
├── public # 静态资源
│ │── favicon.ico # favicon图标
│ └── index.html # html模板
├── src # 源代码
│ ├── api # 所有请求
│ ├── assets # 主题 字体等静态资源
│ ├── components # 全局公用组件
│ ├── directive # 全局指令
│ ├── filters # 全局 filter
│ ├── icons # 项目所有 svg icons
│ ├── lang # 国际化 language
│ ├── layout # 全局 layout
│ ├── router # 路由
│ ├── store # 全局 store管理
│ ├── styles # 全局样式
│ ├── utils # 全局公用方法
│ ├── vendor # 公用vendor
│ ├── views # views 所有页面
│ ├── App.vue # 入口页面
│ ├── main.js # 入口文件 加载组件 初始化等
│ └── permission.js # 权限管理
├── tests # 测试
├── .env.xxx # 环境变量配置
├── .eslintrc.js # eslint 配置项
├── .babelrc # babel-loader 配置
├── .travis.yml # 自动化CI配置
├── vue.config.js # vue-cli 配置
├── postcss.config.js # postcss 配置
└── package.json # package.json
# .env
#版本号
VUE_APP_WEB_VERSION=1.2.7
# eureka 上注册的服务地址,只是测试时候用
VUE_APP_PROXY = 'http://10.122.212.151:8080/myapp'
# 放权路径
VUE_APP_AUTH_REQUESTS_ANT_MATCHERS = '/login,/chat-client,/chat-client/feedback,/kg-graph,/chat-client/note'
# 请求错误中文提示
VUE_APP_ERROR_MESSAGE_DEFAULT=数据异样!
VUE_APP_ERROR_MESSAGE_403=登录已过期或没有权限!
VUE_APP_ERROR_MESSAGE_404=服务器找不到!
VUE_APP_ERROR_MESSAGE_500=服务器错误!
VUE_APP_ERROR_MESSAGE_OTHER=网络走神了,请稍后再试!
# .env.development
# just a flag
ENV = 'development'
# base api 配置开发的基本路径(注意:必须要以 VUE_APP 开头)
VUE_APP_BASE_API = '/myapp'
# 本地开发端口号
VUE_APP_DEV_PORT = 8888
# .env.production
# just a flag
ENV = 'production'
# base api 打包时的根路径
# 构建项目名称
VUE_APP_BASE_API = '/jwics'
# .eslintignore
build/*.js
src/assets
public
dist
# babel.config.js
module.exports = {
presets: ['@vue/app']
}
# vue.config.js 配置
'use strict'
const path = require('path')
function resolve(dir) {
return path.join(__dirname, dir)
}
const name = '我的系统'
module.exports = {
publicPath: './', // https://www.my-app.com/my-app/,则设置 publicPath 为 /my-app/
outputDir: 'dist',
assetsDir: 'static',
productionSourceMap: false, // 生产环境的 source map
devServer: {
port: process.env.VUE_APP_DEV_PORT,
open: false,
https: false,
overlay: { // 浏览器显示日志级别
warnings: true,
errors: true
},
proxy: {
[process.env.VUE_APP_BASE_API]: {
target: process.env.VUE_APP_PROXY,
changeOrigin: true,
// logLevel: 'debug', // 代理日志
pathRewrite: {
['^' + process.env.VUE_APP_BASE_API]: ''
}
}
}
},
configureWebpack: {
name: name,
resolve: {
alias: {
'@': resolve('src')
}
}
},
chainWebpack(config) {
config.plugins.delete('preload')
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('vue')
.use('vue-loader')
.loader('vue-loader')
.tap(options => {
options.compilerOptions.preserveWhitespace = true
return options
})
.end()
config.when(process.env.NODE_ENV === 'development', config =>
config.devtool('cheap-source-map')
)
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
},
echarts: {
name: 'chunk-echarts', // split echarts into a single package
priority: 40, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?echarts(.*)/ // in order to adapt to cnpm
},
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
}
}
})
config.optimization.runtimeChunk('single')
})
}
}