Commit 629e31f0 authored by lipengcheng 's avatar lipengcheng

feat(vue.confi.js): 配置lodash按需引入

parent 492d3157
module.exports = { module.exports = {
presets: ['@vue/cli-plugin-babel/preset'] presets: ['@vue/cli-plugin-babel/preset'],
plugins: ['lodash']
} }
...@@ -31,13 +31,16 @@ ...@@ -31,13 +31,16 @@
}, },
"dependencies": { "dependencies": {
"axios": "^0.20.0", "axios": "^0.20.0",
"babel-plugin-lodash": "^3.3.4",
"core-js": "^3.6.5", "core-js": "^3.6.5",
"lodash": "^4.17.20",
"lodash-webpack-plugin": "^0.11.5",
"register-service-worker": "^1.7.1", "register-service-worker": "^1.7.1",
"vue": "^2.6.11", "vue": "^2.6.11",
"vue-bus": "^1.2.1", "vue-bus": "^1.2.1",
"vue-js-modal": "^2.0.0-rc.6",
"vue-router": "^3.2.0", "vue-router": "^3.2.0",
"vuex": "^3.4.0", "vuex": "^3.4.0"
"vue-js-modal": "^2.0.0-rc.6"
}, },
"config": { "config": {
"commitizen": { "commitizen": {
......
import defaultLayout from '@/components/layout/default.vue' import defaultLayout from '@/components/layout/default.vue'
import layoutA from '@/components/layout/layoutA.vue' import layoutA from '@/components/layout/layoutA.vue'
// const install = Vue => {
const requireComponent = require.context('.', true, /\.vue/)
console.log('requireComponent:', requireComponent)
// requireComponent.keys().forEach(filename => {
// // 每个文件的详细信息
// const config = requireComponent(filename)
// Vue.component(config.default.name, config.default)
// })
// }
export default [defaultLayout, layoutA] export default [defaultLayout, layoutA]
// export default {
// install
// }
// console.log(`procdfdess.env1:`, process.env);
console.log('process.env.NODE_ENV1:', process.env.NODE_ENV) console.log('process.env.NODE_ENV1:', process.env.NODE_ENV)
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin')
module.exports = { module.exports = {
// outputDir: process.env.outputDir, // outputDir: process.env.outputDir,
// assetsDir: 'static', // assetsDir: 'static',
...@@ -21,13 +22,30 @@ module.exports = { ...@@ -21,13 +22,30 @@ module.exports = {
} }
}, },
chainWebpack: (config) => { chainWebpack: (config) => {
if (process.env.NODE_ENV === 'production') {
config.plugin('lodashReplace').use(new LodashModuleReplacementPlugin())
// // 去除 console.log
// config.plugin('uglify').tap(([options]) => {
// return [
// Object.assign(options, {
// uglifyOptions: {
// compress: {
// drop_console: true,
// pure_funcs: ['console.log']
// }
// }
// })
// ]
// })
}
config.module config.module
.rule('eslint') .rule('eslint')
.use('eslint-loader') .use('eslint-loader')
.loader('eslint-loader') .loader('eslint-loader')
.tap((options) => { .tap((options) => {
// 保存自动eslint修复 // 保存自动eslint修复
options.fix = true options.fix = false
return options return options
}) })
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment