Commit 08a83b8f by xinla

打包使用cdn 配置

1 parent bd3dbaf9
......@@ -4,18 +4,18 @@
*/
const envs = {
development: {
DOMAIN: 'http://demo.linkwechat.net',
DOMAIN: 'http://dev.linkwechat.net',
BASE_URL: './', // 路由基础路径
BASE_API: 'http://demo.linkwechat.net/linkwechat-api',
SYSTEM_API: '/linkwechat-api', // 接口基础路径/nginx接口转发路径
BASE_API: 'http://dev.linkwechat.net/linkwechat-dev-api',
SYSTEM_API: '/linkwechat-dev-api', // 接口基础路径/nginx接口转发路径
},
test: {
DOMAIN: 'http://demo.linkwechat.net',
DOMAIN: 'http://dev.linkwechat.net',
BASE_URL: './', // 路由基础路径
BASE_API: 'http://demo.linkwechat.net/linkwechat-api',
SYSTEM_API: '/linkwechat-api',
BASE_API: 'http://dev.linkwechat.net/linkwechat-dev-api',
SYSTEM_API: '/linkwechat-dev-api',
_ISGZIP: true, // 是否开启gzip压缩
_ISCDN: false, // 是否开启cdn加速
_ISCDN: true, // 是否开启cdn加速
},
production: {
DOMAIN: 'http://demo.linkwechat.net',
......@@ -23,7 +23,7 @@ const envs = {
BASE_API: 'http://demo.linkwechat.net/linkwechat-api',
SYSTEM_API: '/linkwechat-api',
_ISGZIP: true, // 是否开启gzip压缩
_ISCDN: false, // 是否开启cdn加速
_ISCDN: true, // 是否开启cdn加速
},
}
const env = Object.assign(
......
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
Router.prototype.push = function push(location) {
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
return originalPush.call(this, location).catch((err) => err)
}
......@@ -72,8 +72,7 @@ const devRoutes = [
{
path: 'detail',
name: 'group-code-analyse',
component: (resolve) =>
require(['@/views/commodityCenter/commodityManage/detail'], resolve),
component: (resolve) => require(['@/views/commodityCenter/commodityManage/detail'], resolve),
meta: {
title: '商品管理',
activeMenu: '/commodityCenter/commodityManage',
......@@ -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
// base: window.lwConfig.BASE_URL,
scrollBehavior: () => ({ y: 0 }),
routes:
process.env.NODE_ENV !== 'development' ? constantRoutes : constantRoutes.concat(devRoutes),
routes: process.env.NODE_ENV !== 'development' ? constantRoutes : constantRoutes.concat(devRoutes),
})
'use strict'
const path = require('path')
const webpack = require('webpack')
function resolve(dir) {
return path.join(__dirname, dir)
}
......@@ -61,12 +61,23 @@ module.exports = {
},
},
},
configureWebpack: {
resolve: {
alias: {
'@': resolve('src'),
},
},
configureWebpack(config) {
config.resolve.alias = {
'@': 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) {
// 修复HMR
......@@ -95,16 +106,12 @@ module.exports = {
})
.end()
// 删除 moment 语言包
config.plugin('ignore').use(new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /zh-cn$/))
config.when(process.env.NODE_ENV !== 'development', (config) => {
// cdn
if (env._ISCDN) {
config.externals = {
vue: 'vue',
'element-ui': 'element-ui',
'vue-router': 'vue-router',
vuex: 'vuex',
axios: 'axios',
}
const cdn = {
// 访问https://unpkg.com/element-ui/lib/theme-chalk/index.css获取最新版本
css: [
......@@ -113,8 +120,8 @@ module.exports = {
],
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/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/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获取最新版本
......@@ -158,11 +165,11 @@ module.exports = {
priority: 10,
chunks: 'initial', // only package third parties that are initially dependent
},
elementUI: {
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
test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
},
// elementUI: {
// 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
// test: /[\\/]node_modules[\\/]_?element-ui(.*)/, // in order to adapt to cnpm
// },
commons: {
name: 'chunk-commons',
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!