123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- const path = require('path')
- const webpack = require('webpack')
- const GitRevisionPlugin = require('git-revision-webpack-plugin')
- const GitRevision = new GitRevisionPlugin()
- const buildDate = JSON.stringify(new Date().toLocaleString())
- const createThemeColorReplacerPlugin = require('./config/plugin.config')
- const CompressionWebpackPlugin = require('compression-webpack-plugin')
- const productionGzipExtensions = ['js', 'css']
- function resolve(dir) {
- return path.join(__dirname, dir)
- }
- function getGitHash() {
- try {
- return GitRevision.version()
- } catch (e) { }
- return 'unknown'
- }
- const isProd = process.env.NODE_ENV === 'production'
- const assetsCDN = {
-
- externals: {
- vue: 'Vue',
- 'vue-router': 'VueRouter',
- vuex: 'Vuex',
- axios: 'axios'
- },
- css: [],
-
- js: [
- '/vue.min.js',
- '/vue-router.min.js',
- '/vuex.min.js',
- '/axios.min.js'
- ]
- }
- const vueConfig = {
- configureWebpack: {
-
- plugins: [
-
- new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
- new webpack.DefinePlugin({
- APP_VERSION: `"${require('./package.json').version}"`,
- GIT_HASH: JSON.stringify(getGitHash()),
- BUILD_DATE: buildDate
- }),
-
- new CompressionWebpackPlugin({
- algorithm: 'gzip',
- test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
- threshold: 10240,
- minRatio: 0.8
- })
- ],
-
- externals: isProd ? assetsCDN.externals : {}
- },
- chainWebpack: (config) => {
- config.resolve.alias
- .set('@$', resolve('src'))
- .set('@assets', resolve('src/assets'))
- .set('@views', resolve('src/views'))
- const svgRule = config.module.rule('svg')
- svgRule.uses.clear()
- svgRule
- .oneOf('inline')
- .resourceQuery(/inline/)
- .use('vue-svg-icon-loader')
- .loader('vue-svg-icon-loader')
- .end()
- .end()
- .oneOf('external')
- .use('file-loader')
- .loader('file-loader')
- .options({
- name: 'assets/[name].[hash:8].[ext]'
- })
-
-
- if (isProd) {
- config.plugin('html').tap(args => {
- args[0].cdn = assetsCDN
- return args
- })
- }
- },
- css: {
- loaderOptions: {
- less: {
- modifyVars: {
-
- 'primary-color': '#2f54eb',
-
-
- },
-
- javascriptEnabled: true
- }
- }
- },
- devServer: {
-
- port: 80,
-
- proxy: {
-
- [process.env.VUE_APP_BASE_API]: {
-
- target: `http://127.0.0.1:8080`,
- changeOrigin: true,
- pathRewrite: {
- ['^' + process.env.VUE_APP_BASE_API]: ''
- }
- }
- },
- disableHostCheck: true
- },
-
- productionSourceMap: false,
- lintOnSave: undefined,
-
- transpileDependencies: []
- }
- if (process.env.VUE_APP_PREVIEW === 'true') {
- console.log('VUE_APP_PREVIEW', true)
-
- vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
- }
- module.exports = vueConfig
|