init
This commit is contained in:
+89
-21
@@ -1,27 +1,48 @@
|
||||
/**
|
||||
* @author chuzhixin 1204505056@qq.com (不想保留author可删除)
|
||||
* @description cli配置
|
||||
*/
|
||||
|
||||
const path = require('path')
|
||||
const {
|
||||
publicPath,
|
||||
assetsDir,
|
||||
outputDir,
|
||||
lintOnSave,
|
||||
transpileDependencies,
|
||||
title,
|
||||
devPort
|
||||
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
|
||||
process.env.VUE_APP_AUTHOR = author
|
||||
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 ''
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
publicPath,
|
||||
assetsDir,
|
||||
outputDir,
|
||||
lintOnSave,
|
||||
transpileDependencies,
|
||||
devServer: {
|
||||
hot: true,
|
||||
@@ -30,20 +51,26 @@ module.exports = {
|
||||
noInfo: false,
|
||||
overlay: {
|
||||
warnings: true,
|
||||
errors: true
|
||||
}
|
||||
errors: true,
|
||||
},
|
||||
},
|
||||
configureWebpack () {
|
||||
configureWebpack() {
|
||||
return {
|
||||
resolve: {
|
||||
alias: {
|
||||
'@': resolve('src'),
|
||||
styles: resolve('src/styles')
|
||||
}
|
||||
}
|
||||
views: resolve('src/views'),
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
new Webpack.ProvidePlugin(providePlugin),
|
||||
new WebpackBar({
|
||||
name: webpackBarName,
|
||||
}),
|
||||
],
|
||||
}
|
||||
},
|
||||
chainWebpack (config) {
|
||||
chainWebpack(config) {
|
||||
config.plugins.delete('preload')
|
||||
config.plugins.delete('prefetch')
|
||||
config.module
|
||||
@@ -71,6 +98,10 @@ module.exports = {
|
||||
.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')
|
||||
@@ -81,21 +112,54 @@ module.exports = {
|
||||
name: 'chunk-libs',
|
||||
test: /[\\/]node_modules[\\/]/,
|
||||
priority: 10,
|
||||
chunks: 'initial'
|
||||
chunks: 'initial',
|
||||
},
|
||||
elementUI: {
|
||||
name: 'chunk-elementUI',
|
||||
priority: 20,
|
||||
test: /[\\/]node_modules[\\/]_?element-ui(.*)/
|
||||
test: /[\\/]node_modules[\\/]_?element-ui(.*)/,
|
||||
},
|
||||
fortawesome: {
|
||||
name: 'chunk-fortawesome',
|
||||
priority: 20,
|
||||
test: /[\\/]node_modules[\\/]_?@fortawesome(.*)/
|
||||
}
|
||||
}
|
||||
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,
|
||||
@@ -104,17 +168,21 @@ module.exports = {
|
||||
sourceMap: true,
|
||||
loaderOptions: {
|
||||
scss: {
|
||||
additionalData (content, loaderContext) {
|
||||
/*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 '@import "~@/styles/variables.scss";' + content
|
||||
}
|
||||
return content
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user