Commit 08a83b8f by xinla

打包使用cdn 配置

1 parent bd3dbaf9
...@@ -4,18 +4,18 @@ ...@@ -4,18 +4,18 @@
*/ */
const envs = { const envs = {
development: { development: {
DOMAIN: 'http://demo.linkwechat.net', DOMAIN: 'http://dev.linkwechat.net',
BASE_URL: './', // 路由基础路径 BASE_URL: './', // 路由基础路径
BASE_API: 'http://demo.linkwechat.net/linkwechat-api', BASE_API: 'http://dev.linkwechat.net/linkwechat-dev-api',
SYSTEM_API: '/linkwechat-api', // 接口基础路径/nginx接口转发路径 SYSTEM_API: '/linkwechat-dev-api', // 接口基础路径/nginx接口转发路径
}, },
test: { test: {
DOMAIN: 'http://demo.linkwechat.net', DOMAIN: 'http://dev.linkwechat.net',
BASE_URL: './', // 路由基础路径 BASE_URL: './', // 路由基础路径
BASE_API: 'http://demo.linkwechat.net/linkwechat-api', BASE_API: 'http://dev.linkwechat.net/linkwechat-dev-api',
SYSTEM_API: '/linkwechat-api', SYSTEM_API: '/linkwechat-dev-api',
_ISGZIP: true, // 是否开启gzip压缩 _ISGZIP: true, // 是否开启gzip压缩
_ISCDN: false, // 是否开启cdn加速 _ISCDN: true, // 是否开启cdn加速
}, },
production: { production: {
DOMAIN: 'http://demo.linkwechat.net', DOMAIN: 'http://demo.linkwechat.net',
...@@ -23,7 +23,7 @@ const envs = { ...@@ -23,7 +23,7 @@ const envs = {
BASE_API: 'http://demo.linkwechat.net/linkwechat-api', BASE_API: 'http://demo.linkwechat.net/linkwechat-api',
SYSTEM_API: '/linkwechat-api', SYSTEM_API: '/linkwechat-api',
_ISGZIP: true, // 是否开启gzip压缩 _ISGZIP: true, // 是否开启gzip压缩
_ISCDN: false, // 是否开启cdn加速 _ISCDN: true, // 是否开启cdn加速
}, },
} }
const env = Object.assign( const env = Object.assign(
......
import Vue from 'vue' import Vue from 'vue'
import Router from 'vue-router' import VueRouter from 'vue-router'
Vue.use(Router) Vue.use(VueRouter)
const originalPush = Router.prototype.push const originalPush = VueRouter.prototype.push
Router.prototype.push = function push(location) { VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err) return originalPush.call(this, location).catch((err) => err)
} }
...@@ -72,8 +72,7 @@ const devRoutes = [ ...@@ -72,8 +72,7 @@ const devRoutes = [
{ {
path: 'detail', path: 'detail',
name: 'group-code-analyse', name: 'group-code-analyse',
component: (resolve) => component: (resolve) => require(['@/views/commodityCenter/commodityManage/detail'], resolve),
require(['@/views/commodityCenter/commodityManage/detail'], resolve),
meta: { meta: {
title: '商品管理', title: '商品管理',
activeMenu: '/commodityCenter/commodityManage', activeMenu: '/commodityCenter/commodityManage',
...@@ -159,10 +158,9 @@ export const constantRoutes = [ ...@@ -159,10 +158,9 @@ export const constantRoutes = [
}, },
] ]
export default new Router({ export default new VueRouter({
// mode: process.env.VUE_APP_ENV === 'test' ? 'hash' : 'history', // history 下 element ui 存在bug // mode: process.env.VUE_APP_ENV === 'test' ? 'hash' : 'history', // history 下 element ui 存在bug
// base: window.lwConfig.BASE_URL, // base: window.lwConfig.BASE_URL,
scrollBehavior: () => ({ y: 0 }), scrollBehavior: () => ({ y: 0 }),
routes: routes: process.env.NODE_ENV !== 'development' ? constantRoutes : constantRoutes.concat(devRoutes),
process.env.NODE_ENV !== 'development' ? constantRoutes : constantRoutes.concat(devRoutes),
}) })
'use strict' 'use strict'
const path = require('path') const path = require('path')
const webpack = require('webpack')
function resolve(dir) { function resolve(dir) {
return path.join(__dirname, dir) return path.join(__dirname, dir)
} }
...@@ -61,12 +61,23 @@ module.exports = { ...@@ -61,12 +61,23 @@ module.exports = {
}, },
}, },
}, },
configureWebpack: { configureWebpack(config) {
resolve: { config.resolve.alias = {
alias: { '@': resolve('src'),
'@': resolve('src'), }
},
}, if (process.env.NODE_ENV !== 'development') {
// cdn
if (env._ISCDN) {
config.externals = {
vue: 'Vue',
'element-ui': 'ELEMENT',
'vue-router': 'VueRouter',
vuex: 'Vuex',
axios: 'axios',
}
}
}
}, },
chainWebpack(config) { chainWebpack(config) {
// 修复HMR // 修复HMR
...@@ -95,16 +106,12 @@ module.exports = { ...@@ -95,16 +106,12 @@ module.exports = {
}) })
.end() .end()
// 删除 moment 语言包
config.plugin('ignore').use(new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn$/))
config.when(process.env.NODE_ENV !== 'development', (config) => { config.when(process.env.NODE_ENV !== 'development', (config) => {
// cdn // cdn
if (env._ISCDN) { if (env._ISCDN) {
config.externals = {
vue: 'vue',
'element-ui': 'element-ui',
'vue-router': 'vue-router',
vuex: 'vuex',
axios: 'axios',
}
const cdn = { const cdn = {
// 访问https://unpkg.com/element-ui/lib/theme-chalk/index.css获取最新版本 // 访问https://unpkg.com/element-ui/lib/theme-chalk/index.css获取最新版本
css: [ css: [
...@@ -113,8 +120,8 @@ module.exports = { ...@@ -113,8 +120,8 @@ module.exports = {
], ],
js: [ js: [
'//cdn.bootcdn.net/ajax/libs/vue/2.6.10/vue.runtime.min.js', '//cdn.bootcdn.net/ajax/libs/vue/2.6.10/vue.runtime.min.js',
'//cdn.bootcdn.net/ajax/libs/vue-router/3.5.3/vue-router.min.js',
'//cdn.bootcdn.net/ajax/libs/vuex/3.1.0/vuex.min.js', '//cdn.bootcdn.net/ajax/libs/vuex/3.1.0/vuex.min.js',
'//cdn.bootcdn.net/ajax/libs/vue-router/3.5.3/vue-router.min.js',
'//cdn.bootcdn.net/ajax/libs/axios/0.26.0/axios.min.js', '//cdn.bootcdn.net/ajax/libs/axios/0.26.0/axios.min.js',
'//cdn.bootcdn.net/ajax/libs/element-ui/2.15.7/index.min.js', '//cdn.bootcdn.net/ajax/libs/element-ui/2.15.7/index.min.js',
// '//unpkg.com/vue@2.6.10/dist/vue.runtime.min.js', // 访问https://unpkg.com/vue/dist/vue.min.js获取最新版本 // '//unpkg.com/vue@2.6.10/dist/vue.runtime.min.js', // 访问https://unpkg.com/vue/dist/vue.min.js获取最新版本
...@@ -158,11 +165,11 @@ module.exports = { ...@@ -158,11 +165,11 @@ module.exports = {
priority: 10, priority: 10,
chunks: 'initial', // only package third parties that are initially dependent chunks: 'initial', // only package third parties that are initially dependent
}, },
elementUI: { // elementUI: {
name: 'chunk-elementUI', // split elementUI into a single package // name: 'chunk-elementUI', // split elementUI into a single package
priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app // priority: 20, // the weight needs to be larger than libs and app or it will be packaged into libs or app
test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm // test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
}, // },
commons: { commons: {
name: 'chunk-commons', name: 'chunk-commons',
test: resolve('src/components'), // can customize your rules test: resolve('src/components'), // can customize your rules
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!