diff --git a/.env.build-lib b/.env.build-lib new file mode 100644 index 0000000..e3d9af9 --- /dev/null +++ b/.env.build-lib @@ -0,0 +1 @@ +NODE_ENV = 'build-lib' \ No newline at end of file diff --git a/.env.development b/.env.development new file mode 100644 index 0000000..254a9ea --- /dev/null +++ b/.env.development @@ -0,0 +1 @@ +NODE_ENV = 'development' \ No newline at end of file diff --git a/.env.production b/.env.production new file mode 100644 index 0000000..53b13b6 --- /dev/null +++ b/.env.production @@ -0,0 +1 @@ +NODE_ENV = 'production' \ No newline at end of file diff --git a/package.json b/package.json index af161ac..53dcf78 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,10 @@ "description": "A visual graph editor based on G6 and Vue.", "main": "dist/xfc.umd.min.js", "scripts": { - "serve": "vue-cli-service serve", - "example": "npx --max_old_space_size=8192 vue-cli-service serve ./example/main.js", - "build": "vue-cli-service build", - "build-package": "vue-cli-service build --target lib --name xfc ./src/xfc.js --dest ./dist --report", + "serve": "vue-cli-service serve --mode development", + "example": "npx --max_old_space_size=4096 vue-cli-service serve --mode development ./example/main.js", + "build": "vue-cli-service build --mode production", + "build-lib": "vue-cli-service build --mode build-lib --target lib --name xfc ./src/xfc.js --dest ./dist --report", "lint": "vue-cli-service lint" }, "repository": { diff --git a/vue.config.js b/vue.config.js index b09e697..1eaac3a 100644 --- a/vue.config.js +++ b/vue.config.js @@ -6,8 +6,6 @@ * 文档:https://cli.vuejs.org/zh/config/ */ -const webpack = require('webpack') - module.exports = { // 部署应用包时的基本URL,置空使用相对路径 publicPath: '/X-Flowchart-Vue/', @@ -48,25 +46,25 @@ module.exports = { '@antv/g6': 'G6', 'iview': 'iview' } - } - , + }, chainWebpack: config => { - const cdn = { - // 访问https://unpkg.com/element-ui/lib/theme-chalk/index.css获取最新版本 - css: ['//unpkg.com/iview@3.4.2/dist/styles/iview.css'], - js: [ - '//unpkg.com/vue@2.6.10/dist/vue.min.js', - '//unpkg.com/vuex@3.0.1/dist/vuex.min.js', - '//unpkg.com/iview@3.4.2/dist/iview.js', - '//unpkg.com/@antv/g6@3.5.6/dist/g6.min.js' - ] - } + config.when(['development', 'production'].includes(process.env.NODE_ENV), config => { + const cdn = { + css: ['//unpkg.com/iview@3.4.2/dist/styles/iview.css'], + js: [ + '//unpkg.com/vue@2.6.10/dist/vue.min.js', + '//unpkg.com/vuex@3.0.1/dist/vuex.min.js', + '//unpkg.com/iview@3.4.2/dist/iview.js', + '//unpkg.com/@antv/g6@3.5.6/dist/g6.min.js' + ] + } - // 如果使用多页面打包,使用vue inspect --plugins查看html是否在结果数组中 - config.plugin('html').tap(args => { - // html中添加cdn - args[0].cdn = cdn - return args + // 如果使用多页面打包,使用vue inspect --plugins查看html是否在结果数组中 + config.plugin('html').tap(args => { + // html中添加cdn + args[0].cdn = cdn + return args + }) }) } }