UNPKG

yks-element

Version:

yks公共库

175 lines (168 loc) 5.31 kB
/** * 打包配置参数 * @String NPM_APP_CDN_URL 静态资源地址 * @String NPM_APP_DEV_URL 开发环境地址 * @String NPM_APP_TEST_URL 测试环境地址 * @String NPM_APP_PRE_URL 预发布环境地址 * @String NPM_APP_PROD_URL 线上环境地址 * @Array cdnConfig 排除打包文件集合 * @Object cdn 引入文件 cdn 链接 * @function setPackParams 设置打包参数 * @function proxy 代理 */ const NPM_APP_CDN_URL = 'https://obs-ogt.obs.cn-east-3.myhuaweicloud.com/assets' const NPM_APP_DEV_URL = 'https://gldev.cetset.com' const NPM_APP_TEST_URL = 'https://gltest.cetset.com' const NPM_APP_PRE_URL = 'https://glpre.yks365.net' const NPM_APP_PROD_URL = 'https://gl.yks365.net' const packages = require('../../package.json') const getConfig = (version, url) => { const cdn = url || NPM_APP_CDN_URL let cdnConfigs = [ { name: 'vue', library: 'Vue', js: `${cdn}/cdn/vue.min@2.6.11.js`, dev: `${cdn}/cdn/vue@2.6.11.js`, css: '' }, { name: 'vuex', library: 'Vuex', js: `${cdn}/cdn/vuex.min@3.3.0.js`, css: '' }, { name: 'vue-router', library: 'VueRouter', js: `${cdn}/cdn/vue-router@3.5.3.js`, css: '' }, { name: 'axios', library: 'axios', js: `${cdn}/cdn/axios.min@0.19.2.js`, css: '' }, { name: 'yks-element', library: 'YKSEMENT', js: `${cdn}/yks-element/${version || packages.version}/yks.js`, css: `${cdn}/yks-element/${version || packages.version}/theme-chalk/index.css` }, { name: 'lodash', library: { commonjs: 'lodash', commonjs2: 'lodash', amd: 'lodash', root: '_' }, js: `${cdn}/cdn/lodash.min@4.17.15.js`, css: '' }, { name: 'echarts', library: 'echarts', js: `${cdn}/cdn/echarts.min@4.7.0.js`, css: '' } ] return cdnConfigs } const externals = () => { let externals = {} let cdnConfig = getConfig().filter((item) => !item.externals) cdnConfig.forEach((pkg) => { externals[pkg.name] = pkg.library === 'Vue' ? `${pkg.library}` : pkg.library }) return externals } const cdn = (env, version, url) => { const cdnConfig = getConfig(version, url) const js = [] const css = [] cdnConfig.forEach((v) => { const value = env === 'development' && v.name === 'vue' ? v.dev : v.js js.push(value) if (v.css && v.css !== '') css.push(v.css) }) return { css, js } } const setPackParams = (config, env, version, url) => { config.plugin('html').tap((args) => { let cdns = cdn(env, version, url) args[0].cdn = cdns return args }) } const proxy = (pro, env, targets) => { if (!pro || !env) { return new Error('pro or env is not difine !') } const params = { dev: NPM_APP_DEV_URL, test: NPM_APP_TEST_URL, pre: NPM_APP_PRE_URL, prod: NPM_APP_PROD_URL } const target = params[env] ? params[env] : targets return { ['/' + pro + '/bm']: { target: target, pathRewrite: { ['^/' + pro + '/bm']: `/${pro}/bm` } }, ['/' + pro + '/pj']: { target: target, pathRewrite: { ['^/' + pro + '/pj']: `/${pro}/pj` } }, ['/' + pro + '/ua']: { target: target, pathRewrite: { ['^/' + pro + '/ua']: `/${pro}/ua` } }, ['/' + pro + '/gov']: { target: target, pathRewrite: { ['^/' + pro + '/gov']: `/${pro}/gov` } }, ['/' + pro + '/kw']: { target: target, pathRewrite: { ['^/' + pro + '/kw']: `/${pro}/kw` } }, ['/' + pro + '/pt']: { target: target, pathRewrite: { ['^/' + pro + '/pt']: `/${pro}/pt` } }, ['/' + pro + '/cj']: { target: target, pathRewrite: { ['^/' + pro + '/cj']: `/${pro}/cj` } }, ['/' + pro + '/api']: { target: target, pathRewrite: { ['^/' + pro + '/api']: `/${pro}/api` } }, ['/' + pro + '/login']: { target: target, pathRewrite: { ['^/' + pro + '/login']: `/${pro}/login` } }, ['/' + pro + '/tps']: { target: target, pathRewrite: { ['^/' + pro + '/tps']: `/${pro}/tps` } }, ['/' + pro + '/tk']: { target: target, pathRewrite: { ['^/' + pro + '/tk']: `/${pro}/tk` } }, ['/' + pro + '/ks']: { target: target, pathRewrite: { ['^/' + pro + '/ks']: `/${pro}/ks` } } } } module.exports = { proxy, externals, setPackParams }