123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- /**
- * @description vue.config.js全局配置
- */
- const path = require('path')
- const {
- baseURL,
- publicPath,
- assetsDir,
- outputDir,
- lintOnSave,
- transpileDependencies,
- title,
- abbreviation,
- devPort,
- providePlugin,
- build7z,
- buildGzip,
- imageCompression,
- } = require('./src/config')
- const rely = require('vue-plugin-rely')
- const { webpackBarName, webpackBanner } = require('./vab.config')
- const { version, author } = require('./package.json')
- const Webpack = require('webpack')
- const WebpackBar = require('webpackbar')
- const FileManagerPlugin = require('filemanager-webpack-plugin')
- const dayjs = require('dayjs')
- const dateTime = dayjs().format('YYYY-M-D HH:mm:ss')
- const CompressionWebpackPlugin = require('compression-webpack-plugin')
- const productionGzipExtensions = ['html', 'js', 'css', 'svg']
- process.env.VUE_APP_TITLE = title
- process.env.VUE_APP_AUTHOR = author
- process.env.VUE_APP_UPDATE_TIME = dateTime
- process.env.VUE_APP_VERSION = version
- process.env.VUE_APP_RELY = rely
- const resolve = (dir) => {
- return path.join(__dirname, dir)
- }
- module.exports = {
- publicPath,
- assetsDir,
- outputDir,
- lintOnSave,
- transpileDependencies,
- devServer: {
- hot: true,
- port: devPort,
- open: true,
- noInfo: false,
- overlay: {
- warnings: true,
- errors: true,
- },
- // 注释掉的地方是前端配置代理访问后端的示例
- // baseURL必须为/xxx,而不是后端服务器,请先了解代理逻辑,再设置前端代理
- // !!!一定要注意!!!
- // 1.这里配置了跨域及代理只针对开发环境生效
- // 2.不建议你在前端配置跨域,建议你后端配置Allow-Origin,Method,Headers,放行token字段,一步到位
- // 3.后端配置了跨域,就不需要前端再配置,会发生Origin冲突
- proxy: {
- [baseURL]: {
- target: `https://api.remote.site.ximengnaikang.com/admin`,
- //target: `http://api.review.site.ximengnaikang.com`,
- ws: true,
- changeOrigin: true,
- pathRewrite: {
- ['^' + baseURL]: '',
- },
- },
- },
- after: require('./mock'),
- },
- configureWebpack() {
- return {
- resolve: {
- alias: {
- '~': resolve('.'),
- '@': resolve('src'),
- },
- },
- plugins: [
- new Webpack.ProvidePlugin(providePlugin),
- new WebpackBar({
- name: webpackBarName,
- }),
- ],
- }
- },
- chainWebpack(config) {
- config.resolve.symlinks(true)
- config.module.rule('svg').exclude.add(resolve('src/icon'))
- config.module
- .rule('vabIcon')
- .test(/\.svg$/)
- .include.add(resolve('src/icon'))
- .end()
- .use('svg-sprite-loader')
- .loader('svg-sprite-loader')
- .options({ symbolId: 'vab-icon-[name]' })
- config.when(process.env.NODE_ENV === 'development', (config) => {
- config.devtool('source-map')
- })
- config.when(process.env.NODE_ENV === 'production', (config) => {
- config.performance.set('hints', false)
- config.devtool('none')
- config.optimization.splitChunks({
- automaticNameDelimiter: '-',
- chunks: 'all',
- cacheGroups: {
- chunk: {
- name: 'chunk',
- test: /[\\/]node_modules[\\/]/,
- minSize: 131072,
- maxSize: 524288,
- chunks: 'async',
- minChunks: 2,
- priority: 10,
- },
- vue: {
- name: 'vue',
- test: /[\\/]node_modules[\\/](vue(.*)|core-js)[\\/]/,
- chunks: 'initial',
- priority: 20,
- },
- elementUI: {
- name: 'element-ui',
- test: /[\\/]node_modules[\\/]element-ui(.*)[\\/]/,
- priority: 30,
- },
- extra: {
- name: 'extra',
- test: resolve('src/extra'),
- priority: 40,
- },
- // 根据使用模块抽取公共代码
- // echarts: {
- // name: 'echarts',
- // test: /[\\/]node_modules[\\/](echarts|zrender|tslib)[\\/]/,
- // priority: 50,
- // },
- },
- })
- config
- .plugin('banner')
- .use(Webpack.BannerPlugin, [`${webpackBanner}${dateTime}`])
- if (imageCompression)
- config.module
- .rule('images')
- .use('image-webpack-loader')
- .loader('image-webpack-loader')
- .options({
- bypassOnDebug: true,
- })
- .end()
- if (buildGzip)
- config.plugin('compression').use(CompressionWebpackPlugin, [
- {
- filename: '[path][base].gz[query]',
- algorithm: 'gzip',
- test: new RegExp(
- '\\.(' + productionGzipExtensions.join('|') + ')$'
- ),
- threshold: 8192,
- minRatio: 0.8,
- },
- ])
- if (build7z)
- config.plugin('fileManager').use(FileManagerPlugin, [
- {
- events: {
- onEnd: {
- archive: [
- {
- source: `./${outputDir}`,
- destination: `./${outputDir}/${abbreviation}_${dayjs().unix()}.zip`,
- },
- ],
- },
- },
- },
- ])
- })
- },
- runtimeCompiler: true,
- productionSourceMap: false,
- css: {
- requireModuleExtension: true,
- sourceMap: true,
- loaderOptions: {
- scss: {
- additionalData(content, loaderContext) {
- const { resourcePath, rootContext } = loaderContext
- const relativePath = path.relative(rootContext, resourcePath)
- if (
- relativePath.replace(/\\/g, '/') !==
- 'src/vab/styles/variables/variables.scss'
- )
- return '@import "~@/vab/styles/variables/variables.scss";' + content
- return content
- },
- },
- },
- },
- }
|