1 Star 0 Fork 0

d_benhua / ControlManage

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
vue.config.js 5.32 KB
一键复制 编辑 原始数据 按行查看 历史
d_benhua 提交于 2021-10-12 15:55 . 初始提交
const path = require('path')
const webpack = require('webpack')
const {
IgnorePlugin,
} = require('webpack')
const {
createMockMiddleware,
} = require('umi-mock-middleware')
const {
BundleAnalyzerPlugin,
} = require('webpack-bundle-analyzer')
const createThemeColorReplacerPlugin = require('./config/theme.plugin')
const GitRevisionPlugin = require('git-revision-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const GitRevision = new GitRevisionPlugin()
const buildDate = JSON.stringify(new Date().toLocaleString())
// const isProd = process.env.NODE_ENV === 'production'
const isUseCDN = process.env.IS_USE_CDN === 'true'
const isAnalyz = process.env.IS_ANALYZ === 'true'
function resolve (dir) {
return path.join(__dirname, dir)
}
// check Git
function getGitHash () {
try {
return GitRevision.version()
} catch (e) {
}
return 'unknown'
}
const assetsCDN = {
externals: {
vue: 'Vue',
vuex: 'Vuex',
'vue-router': 'VueRouter',
'AMap': 'AMap',
'BMap': 'BMap',
'BMapLib': 'BMapLib',
'IMAP': 'mapabcgl',
},
assets: {
css: [],
// https://unpkg.com/:package@:version/:file
// https://cdn.jsdelivr.net/package:version/:file
js: [
'//cdn.jsdelivr.net/npm/vue@latest/dist/vue.min.js',
'//cdn.jsdelivr.net/npm/vue-router@latest/dist/vue-router.min.js',
'//cdn.jsdelivr.net/npm/vuex@latest/dist/vuex.min.js',
],
},
}
// vue.config
const vueConfig = {
runtimeCompiler: true,
configureWebpack: {
plugins: [
// Ignore all locale files of moment.js
new IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.DefinePlugin({
APP_VERSION: `"${require('./package.json').version}"`,
GIT_HASH: JSON.stringify(getGitHash()),
BUILD_DATE: buildDate,
}),
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
}),
new webpack.ProvidePlugin({
flvjs: 'flvjs',
}),
new CopyWebpackPlugin([
{ from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer-lib.min.js', to: 'js/' },
{ from: 'node_modules/@liveqing/liveplayer/dist/component/liveplayer.swf' },
]),
],
resolve: {
alias: {
'@ant-design/icons/lib/dist$': resolve('./src/icons.js'),
'flvjs': resolve('./src/lib/video/flv.js'),
},
},
externals: isUseCDN ? assetsCDN.externals : {
'AMap': 'AMap',
'BMap': 'BMap',
'BMapLib': 'BMapLib',
'IMAP': 'mapabcgl',
},
},
chainWebpack: config => {
// replace svg-loader
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 `IS_USE_CDN` env is TRUE require on cdn assets
isUseCDN && config.plugin('html').tap(args => {
args[0].cdn = assetsCDN.assets
return args
})
// if `IS_ANALYZ` env is TRUE on report bundle info
isAnalyz && config.plugin('webpack-report').use(BundleAnalyzerPlugin, [{
analyzerMode: 'static',
}])
},
// style config
css: {
loaderOptions: {
less: {
modifyVars: {
// 覆盖ant design 默认样式
'border-radius-base': '2px',
'layout-header-height': '64px',
},
// DO NOT REMOVE THIS LINE
javascriptEnabled: true,
},
},
},
devServer: {
// development server port 8000
port: 8000,
// mock serve
before: app => {
if (process.env.DisableMOCK !== 'true') {
app.use(createMockMiddleware())
}
},
// If you want to turn on the proxy, please remove the mockjs /src/main.jsL11
proxy: {
'/api': {
// target: 'http://183.221.84.110:8081',
// target:'https://b4a91255-e1e5-46c3-bc65-9754e5ade873.mock.pstmn.io',//1000次受限
// target: 'https://86b42953-381c-4d9d-a6d8-057afaa5acbd.mock.pstmn.io',
// target: 'http://113.54.214.141:8089',
target: '211.83.106.189:8089',
// target: 'https://mockapi.eolinker.com/ZZfVVLXf0572bfc016793a61c16944786c0c9de16a2edd7/Semaphore',
ws: false,
changeOrigin: true,
pathRewrite: {
'^/api': '',
},
},
'/amap': {
target: 'https://restapi.amap.com/',
ws: false,
changeOrigin: true,
pathRewrite: {
'^/amap': '',
},
},
'/bmap': {
target: 'http://api.map.baidu.com/',
ws: false,
changeOrigin: true,
pathRewrite: {
'^/bmap': '',
},
},
'/ws': {
target: 'ws://183.221.84.110:8081',
ws: true,
changeOrigin: true,
pathRewrite: {
'^/ws': '',
},
},
},
},
/* ADVANCED SETTINGS */
// disable source map in production
productionSourceMap: false,
// ESLint Check: DISABL,E for false
// Type: boolean | 'warning' | 'default' | 'error'
// 请安装eline 插件,按照规范修改。
lintOnSave: false,
// babel-loader no-ignore node_modules/*
transpileDependencies: [],
}
vueConfig.configureWebpack.plugins.push(createThemeColorReplacerPlugin())
module.exports = vueConfig
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/d-benhua/control-manage.git
git@gitee.com:d-benhua/control-manage.git
d-benhua
control-manage
ControlManage
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891