code init
This commit is contained in:
+91
-177
@@ -1,183 +1,97 @@
|
||||
const webpack = require('webpack')
|
||||
const { interfaceUrl } = require('./src/sysConfig')
|
||||
const path = require('path')
|
||||
const {
|
||||
publicPath,
|
||||
assetsDir,
|
||||
outputDir,
|
||||
lintOnSave,
|
||||
transpileDependencies,
|
||||
title,
|
||||
abbreviation,
|
||||
devPort,
|
||||
providePlugin,
|
||||
build7z,
|
||||
donation,
|
||||
} = require('./src/config')
|
||||
const { webpackBarName, webpackBanner, donationConsole } = require('zx-layouts')
|
||||
|
||||
if (donation) donationConsole()
|
||||
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 date = dayjs().format('YYYY_M_D')
|
||||
const time = dayjs().format('YYYY-M-D HH:mm:ss')
|
||||
process.env.VUE_APP_TITLE = title || 'vue-admin-beautiful'
|
||||
process.env.VUE_APP_AUTHOR = author || 'chuzhixin 1204505056@qq.com'
|
||||
process.env.VUE_APP_UPDATE_TIME = time
|
||||
process.env.VUE_APP_VERSION = version
|
||||
|
||||
const resolve = (dir) => path.join(__dirname, dir)
|
||||
const mockServer = () => {
|
||||
if (process.env.NODE_ENV === 'development') return require('./mock')
|
||||
else return ''
|
||||
function resolve(dir) {
|
||||
return path.join(__dirname, dir)
|
||||
}
|
||||
|
||||
const Timestamp = new Date().getTime()
|
||||
module.exports = {
|
||||
publicPath,
|
||||
assetsDir,
|
||||
outputDir,
|
||||
lintOnSave,
|
||||
transpileDependencies,
|
||||
devServer: {
|
||||
hot: true,
|
||||
port: devPort,
|
||||
open: true,
|
||||
noInfo: false,
|
||||
overlay: {
|
||||
warnings: true,
|
||||
errors: true,
|
||||
},
|
||||
},
|
||||
configureWebpack() {
|
||||
return {
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve('src'),
|
||||
views: resolve('src/views'),
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new Webpack.ProvidePlugin(providePlugin),
|
||||
new WebpackBar({
|
||||
name: webpackBarName,
|
||||
}),
|
||||
],
|
||||
}
|
||||
},
|
||||
chainWebpack(config) {
|
||||
config.plugins.delete('preload')
|
||||
config.plugins.delete('prefetch')
|
||||
config.module
|
||||
.rule('svg')
|
||||
.exclude.add(resolve('src/remixIcon'))
|
||||
.add(resolve('src/colorfulIcon'))
|
||||
.end()
|
||||
|
||||
config.module
|
||||
.rule('remixIcon')
|
||||
.test(/\.svg$/)
|
||||
.include.add(resolve('src/remixIcon'))
|
||||
.end()
|
||||
.use('svg-sprite-loader')
|
||||
.loader('svg-sprite-loader')
|
||||
.options({ symbolId: 'remix-icon-[name]' })
|
||||
.end()
|
||||
|
||||
config.module
|
||||
.rule('colorfulIcon')
|
||||
.test(/\.svg$/)
|
||||
.include.add(resolve('src/colorfulIcon'))
|
||||
.end()
|
||||
.use('svg-sprite-loader')
|
||||
.loader('svg-sprite-loader')
|
||||
.options({ symbolId: 'colorful-icon-[name]' })
|
||||
.end()
|
||||
|
||||
/* config.when(process.env.NODE_ENV === "development", (config) => {
|
||||
config.devtool("source-map");
|
||||
}); */
|
||||
config.when(process.env.NODE_ENV !== 'development', (config) => {
|
||||
config.performance.set('hints', false)
|
||||
config.devtool('none')
|
||||
config.optimization.splitChunks({
|
||||
chunks: 'all',
|
||||
cacheGroups: {
|
||||
libs: {
|
||||
name: 'chunk-libs',
|
||||
test: /[\\/]node_modules[\\/]/,
|
||||
priority: 10,
|
||||
chunks: 'initial',
|
||||
},
|
||||
elementUI: {
|
||||
name: 'chunk-elementUI',
|
||||
priority: 20,
|
||||
test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
|
||||
},
|
||||
fortawesome: {
|
||||
name: 'chunk-fortawesome',
|
||||
priority: 20,
|
||||
test: /[\\/]node_modules[\\/]_?@fortawesome(.*)/,
|
||||
},
|
||||
},
|
||||
})
|
||||
config
|
||||
.plugin('banner')
|
||||
.use(Webpack.BannerPlugin, [`${webpackBanner}${time}`])
|
||||
.end()
|
||||
config.module
|
||||
.rule('images')
|
||||
.use('image-webpack-loader')
|
||||
.loader('image-webpack-loader')
|
||||
.options({
|
||||
bypassOnDebug: true,
|
||||
})
|
||||
.end()
|
||||
})
|
||||
|
||||
if (build7z) {
|
||||
config.when(process.env.NODE_ENV === 'production', (config) => {
|
||||
config
|
||||
.plugin('fileManager')
|
||||
.use(FileManagerPlugin, [
|
||||
{
|
||||
onEnd: {
|
||||
delete: [`./${outputDir}/video`, `./${outputDir}/data`],
|
||||
archive: [
|
||||
{
|
||||
source: `./${outputDir}`,
|
||||
destination: `./${outputDir}/${abbreviation}_${outputDir}_${date}.7z`,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
])
|
||||
.end()
|
||||
})
|
||||
}
|
||||
},
|
||||
runtimeCompiler: true,
|
||||
productionSourceMap: false,
|
||||
css: {
|
||||
requireModuleExtension: true,
|
||||
sourceMap: true,
|
||||
loaderOptions: {
|
||||
scss: {
|
||||
/*sass-loader 8.0语法 */
|
||||
//prependData: '@import "~@/styles/variables.scss";',
|
||||
|
||||
/*sass-loader 9.0写法,感谢github用户 shaonialife*/
|
||||
additionalData(content, loaderContext) {
|
||||
const { resourcePath, rootContext } = loaderContext
|
||||
const relativePath = path.relative(rootContext, resourcePath)
|
||||
if (
|
||||
relativePath.replace(/\\/g, '/') !== 'src/styles/variables.scss'
|
||||
) {
|
||||
return '@import "~@/styles/variables.scss";' + content
|
||||
}
|
||||
return content
|
||||
},
|
||||
},
|
||||
},
|
||||
publicPath: './',
|
||||
outputDir: 'dist',
|
||||
assetsDir: 'static',
|
||||
lintOnSave: false,
|
||||
// webpack插件
|
||||
configureWebpack: {
|
||||
plugins: [
|
||||
new webpack.ProvidePlugin({
|
||||
$: 'jquery',
|
||||
jQuery: 'jquery',
|
||||
'windows.jQuery': 'jquery'
|
||||
})
|
||||
]
|
||||
},
|
||||
transpileDependencies: ['node_modules/webpack-dev-server/client', 'element-ui', '@antv/g6'],
|
||||
// webpack配置项
|
||||
chainWebpack: (config) => {
|
||||
config.entry.app = ['@babel/polyfill', './src/main.js']
|
||||
config.module.rule('compile')
|
||||
.test(/\.js$/)
|
||||
.include
|
||||
.add(resolve('src'))
|
||||
.add(resolve('test'))
|
||||
.add(resolve('static'))
|
||||
.add(resolve('node_modules/webpack-dev-server/client'))
|
||||
.add(resolve('node_modules'))
|
||||
.end()
|
||||
.use('babel')
|
||||
.loader('babel-loader')
|
||||
.options({
|
||||
presets: [
|
||||
['@babel/preset-env', {
|
||||
modules: false
|
||||
}]
|
||||
]
|
||||
})
|
||||
config.resolve.alias
|
||||
.set('@', resolve('./src'))
|
||||
.set('module', resolve('./src/module'))
|
||||
.set('assets', resolve('./src/assets'))
|
||||
.set('styles', resolve('./src/assets/styles'))
|
||||
.set('api', resolve('./src/api'))
|
||||
.set('zTree', resolve('./src/assets/zTree'))
|
||||
.set('process', resolve('./src/pages/processCenter/pages'))
|
||||
if (process.env.NODE_ENV === 'production') {
|
||||
// 给js和css配置版本号
|
||||
config.output.filename('js/[name].' + Timestamp + '.js').end();
|
||||
config.output.chunkFilename('js/[name].' + Timestamp + '.js').end();
|
||||
config.plugin('extract-css').tap(args => [{
|
||||
filename: `css/[name].${Timestamp}.css`,
|
||||
chunkFilename: `css/[name].${Timestamp}.css`
|
||||
}])
|
||||
|
||||
config.optimization
|
||||
.minimizer('terser')
|
||||
.tap(args => {
|
||||
const {
|
||||
terserOptions: {
|
||||
compress
|
||||
}
|
||||
} = args[0]
|
||||
compress.drop_console = true
|
||||
compress.drop_debugger = true
|
||||
return args
|
||||
})
|
||||
|
||||
}
|
||||
},
|
||||
devServer: {
|
||||
port: 9999,
|
||||
proxy: {
|
||||
'/api': {
|
||||
target: interfaceUrl,
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^/api': ''
|
||||
}
|
||||
},
|
||||
'/onlyOffice': {
|
||||
target: 'http://172.20.10.2:8888',
|
||||
changeOrigin: true,
|
||||
pathRewrite: {
|
||||
'^/onlyOffice': '/api'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user