张恒

修正当选择为web打包时出现报错得问题

...@@ -9,6 +9,7 @@ const MinifyPlugin = require("babel-minify-webpack-plugin"); ...@@ -9,6 +9,7 @@ const MinifyPlugin = require("babel-minify-webpack-plugin");
9 const CopyWebpackPlugin = require('copy-webpack-plugin') 9 const CopyWebpackPlugin = require('copy-webpack-plugin')
10 const MiniCssExtractPlugin = require('mini-css-extract-plugin') 10 const MiniCssExtractPlugin = require('mini-css-extract-plugin')
11 const HtmlWebpackPlugin = require('html-webpack-plugin') 11 const HtmlWebpackPlugin = require('html-webpack-plugin')
12 +const TerserPlugin = require('terser-webpack-plugin');
12 const { VueLoaderPlugin } = require('vue-loader') 13 const { VueLoaderPlugin } = require('vue-loader')
13 14
14 function resolve(dir) { 15 function resolve(dir) {
...@@ -87,6 +88,7 @@ let webConfig = { ...@@ -87,6 +88,7 @@ let webConfig = {
87 use: { 88 use: {
88 loader: 'url-loader', 89 loader: 'url-loader',
89 query: { 90 query: {
91 + esModule: false,
90 limit: 10000, 92 limit: 10000,
91 name: 'imgs/[name].[ext]' 93 name: 'imgs/[name].[ext]'
92 } 94 }
...@@ -97,6 +99,7 @@ let webConfig = { ...@@ -97,6 +99,7 @@ let webConfig = {
97 use: { 99 use: {
98 loader: 'url-loader', 100 loader: 'url-loader',
99 query: { 101 query: {
102 + esModule: false,
100 limit: 10000, 103 limit: 10000,
101 name: 'fonts/[name].[ext]' 104 name: 'fonts/[name].[ext]'
102 } 105 }
...@@ -159,6 +162,50 @@ if (process.env.NODE_ENV === 'production') { ...@@ -159,6 +162,50 @@ if (process.env.NODE_ENV === 'production') {
159 minimize: true 162 minimize: true
160 }) 163 })
161 ) 164 )
165 + webConfig.optimization = {
166 + splitChunks: {
167 + chunks: "async",
168 + cacheGroups: {
169 + vendor: { // 将第三方模块提取出来
170 + minSize: 30000,
171 + minChunks: 1,
172 + test: /node_modules/,
173 + chunks: 'initial',
174 + name: 'vendor',
175 + priority: 1
176 + },
177 + commons: {
178 + test: /[\\/]src[\\/]common[\\/]/,
179 + name: 'commons',
180 + minSize: 30000,
181 + minChunks: 3,
182 + chunks: 'initial',
183 + priority: -1,
184 + reuseExistingChunk: true // 这个配置允许我们使用已经存在的代码块
185 + }
186 + }
187 + },
188 + runtimeChunk: { name: 'runtime' },
189 + minimizer: [
190 + new TerserPlugin({
191 + test: /\.js(\?.*)?$/i,
192 + extractComments: false,
193 + cache: false,
194 + sourceMap: false,
195 + terserOptions: {
196 + warnings: false,
197 + compress: {
198 + warnings: false,
199 + drop_console: true,
200 + drop_debugger: true,
201 + pure_funcs: ['console.log']
202 + },
203 + output: {
204 + comments: false,
205 + },
206 + }
207 + })]
208 + }
162 } 209 }
163 210
164 module.exports = webConfig 211 module.exports = webConfig
......
...@@ -42,6 +42,7 @@ npm config edit ...@@ -42,6 +42,7 @@ npm config edit
42 这是花裤衩大大原本的[地址](https://github.com/PanJiaChen/electron-vue-admin) 42 这是花裤衩大大原本的[地址](https://github.com/PanJiaChen/electron-vue-admin)
43 43
44 # 更新日志 44 # 更新日志
45 +- 2020年04月29日:添加了路由多窗口示例,修复web打包,提升依赖;文档还未就绪
45 - 2020年02月09日:添加[中文在线文档](https://umbrella22.github.io/electron-vue-template-doc/)[国内访问地址](https://zh-sky.gitee.io/electron-vue-template-doc/) 46 - 2020年02月09日:添加[中文在线文档](https://umbrella22.github.io/electron-vue-template-doc/)[国内访问地址](https://zh-sky.gitee.io/electron-vue-template-doc/)
46 - 剔除win打包依赖,因为太大了,将它放到码云的额外仓库中,[地址](https://gitee.com/Zh-Sky/HardToDownloadLib) 47 - 剔除win打包依赖,因为太大了,将它放到码云的额外仓库中,[地址](https://gitee.com/Zh-Sky/HardToDownloadLib)
47 - 2020年02月06日更新:激进分支更新至8.0.0. 48 - 2020年02月06日更新:激进分支更新至8.0.0.
......
...@@ -9700,7 +9700,7 @@ ...@@ -9700,7 +9700,7 @@
9700 }, 9700 },
9701 "matcher": { 9701 "matcher": {
9702 "version": "2.1.0", 9702 "version": "2.1.0",
9703 - "resolved": "https://registry.npm.taobao.org/matcher/download/matcher-2.1.0.tgz", 9703 + "resolved": "https://registry.npm.taobao.org/matcher/download/matcher-2.1.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fmatcher%2Fdownload%2Fmatcher-2.1.0.tgz",
9704 "integrity": "sha1-ZOEEHBW5k+I7eG+TMgp0dL+DPCg=", 9704 "integrity": "sha1-ZOEEHBW5k+I7eG+TMgp0dL+DPCg=",
9705 "dev": true, 9705 "dev": true,
9706 "optional": true, 9706 "optional": true,
...@@ -9710,7 +9710,7 @@ ...@@ -9710,7 +9710,7 @@
9710 "dependencies": { 9710 "dependencies": {
9711 "escape-string-regexp": { 9711 "escape-string-regexp": {
9712 "version": "2.0.0", 9712 "version": "2.0.0",
9713 - "resolved": "https://registry.npm.taobao.org/escape-string-regexp/download/escape-string-regexp-2.0.0.tgz", 9713 + "resolved": "https://registry.npm.taobao.org/escape-string-regexp/download/escape-string-regexp-2.0.0.tgz?cache=0&sync_timestamp=1586278520081&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fescape-string-regexp%2Fdownload%2Fescape-string-regexp-2.0.0.tgz",
9714 "integrity": "sha1-owME6Z2qMuI7L9IPUbq9B8/8o0Q=", 9714 "integrity": "sha1-owME6Z2qMuI7L9IPUbq9B8/8o0Q=",
9715 "dev": true, 9715 "dev": true,
9716 "optional": true 9716 "optional": true
...@@ -11402,7 +11402,7 @@ ...@@ -11402,7 +11402,7 @@
11402 }, 11402 },
11403 "posthtml": { 11403 "posthtml": {
11404 "version": "0.9.2", 11404 "version": "0.9.2",
11405 - "resolved": "https://registry.npm.taobao.org/posthtml/download/posthtml-0.9.2.tgz", 11405 + "resolved": "https://registry.npm.taobao.org/posthtml/download/posthtml-0.9.2.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fposthtml%2Fdownload%2Fposthtml-0.9.2.tgz",
11406 "integrity": "sha1-9MBtufZ7Yf0XxOJW5+PZUVv3Jv0=", 11406 "integrity": "sha1-9MBtufZ7Yf0XxOJW5+PZUVv3Jv0=",
11407 "dev": true, 11407 "dev": true,
11408 "requires": { 11408 "requires": {
......
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
54 54
55 <script> 55 <script>
56 import SystemInformation from "./LandingPage/SystemInformation"; 56 import SystemInformation from "./LandingPage/SystemInformation";
57 -import ipcApi from "../utils/ipcRenderer";
58 import { message } from "@/api/login"; 57 import { message } from "@/api/login";
59 export default { 58 export default {
60 name: "landing-page", 59 name: "landing-page",
...@@ -87,7 +86,7 @@ export default { ...@@ -87,7 +86,7 @@ export default {
87 let data = { 86 let data = {
88 url:'/form/index' 87 url:'/form/index'
89 } 88 }
90 - ipcApi.send("open-win", data); 89 + this.$ipcApi.send("open-win", data);
91 }, 90 },
92 getMessage() { 91 getMessage() {
93 message().then(res => { 92 message().then(res => {
...@@ -97,8 +96,8 @@ export default { ...@@ -97,8 +96,8 @@ export default {
97 }); 96 });
98 }, 97 },
99 StartServer() { 98 StartServer() {
100 - ipcApi.send("statr-server"); 99 + this.$ipcApi.send("statr-server");
101 - ipcApi.on("confirm-start", (event, arg) => { 100 + this.$ipcApi.on("confirm-start", (event, arg) => {
102 console.log(arg); 101 console.log(arg);
103 this.$message({ 102 this.$message({
104 type: "success", 103 type: "success",
...@@ -137,8 +136,8 @@ export default { ...@@ -137,8 +136,8 @@ export default {
137 noLink: true, 136 noLink: true,
138 message: "此操作会清空本地数据库中的所有数据,是否继续?" 137 message: "此操作会清空本地数据库中的所有数据,是否继续?"
139 }; 138 };
140 - ipcApi.send("open-messagebox", data); 139 + this.$ipcApi.send("open-messagebox", data);
141 - ipcApi.on("confirm-message", (event, arg) => { 140 + this.$ipcApi.on("confirm-message", (event, arg) => {
142 console.log(arg); 141 console.log(arg);
143 if (arg.response === 0) { 142 if (arg.response === 0) {
144 this.$db.deleall({ name: "yyy" }).then(res => { 143 this.$db.deleall({ name: "yyy" }).then(res => {
...@@ -154,7 +153,7 @@ export default { ...@@ -154,7 +153,7 @@ export default {
154 title: "错误", 153 title: "错误",
155 message: "已经没有数据可以被删除!" 154 message: "已经没有数据可以被删除!"
156 }; 155 };
157 - ipcApi.send("open-errorbox", errormsg); 156 + this.$ipcApi.send("open-errorbox", errormsg);
158 } 157 }
159 }); 158 });
160 } 159 }
...@@ -164,9 +163,9 @@ export default { ...@@ -164,9 +163,9 @@ export default {
164 switch (data) { 163 switch (data) {
165 case "one": 164 case "one":
166 const dialog = this.$electron.remote.dialog; 165 const dialog = this.$electron.remote.dialog;
167 - ipcApi.send("check-update"); 166 + this.$ipcApi.send("check-update");
168 console.log("启动检查"); 167 console.log("启动检查");
169 - ipcApi.on("UpdateMsg", (event, data) => { 168 + this.$ipcApi.on("UpdateMsg", (event, data) => {
170 console.log(data); 169 console.log(data);
171 switch (data.state) { 170 switch (data.state) {
172 case -1: 171 case -1:
...@@ -196,7 +195,7 @@ export default { ...@@ -196,7 +195,7 @@ export default {
196 this.$alert("更新下载完成!", "提示", { 195 this.$alert("更新下载完成!", "提示", {
197 confirmButtonText: "确定", 196 confirmButtonText: "确定",
198 callback: action => { 197 callback: action => {
199 - ipcApi.send("confirm-update"); 198 + this.$ipcApi.send("confirm-update");
200 } 199 }
201 }); 200 });
202 break; 201 break;
...@@ -208,34 +207,34 @@ export default { ...@@ -208,34 +207,34 @@ export default {
208 break; 207 break;
209 case "two": 208 case "two":
210 console.log(111); 209 console.log(111);
211 - ipcApi.send("start-download"); 210 + this.$ipcApi.send("start-download");
212 - ipcApi.on("confirm-download", (event, arg) => { 211 + this.$ipcApi.on("confirm-download", (event, arg) => {
213 if (arg) { 212 if (arg) {
214 this.dialogVisible = true; 213 this.dialogVisible = true;
215 } 214 }
216 }); 215 });
217 - ipcApi.on("download-progress", (event, arg) => { 216 + this.$ipcApi.on("download-progress", (event, arg) => {
218 this.percentage = Number(arg); 217 this.percentage = Number(arg);
219 }); 218 });
220 - ipcApi.on("download-error", (event, arg) => { 219 + this.$ipcApi.on("download-error", (event, arg) => {
221 if (arg) { 220 if (arg) {
222 this.progressStaus = "exception"; 221 this.progressStaus = "exception";
223 this.percentage = 40; 222 this.percentage = 40;
224 this.colors = "#d81e06"; 223 this.colors = "#d81e06";
225 } 224 }
226 }); 225 });
227 - ipcApi.on("download-paused", (event, arg) => { 226 + this.$ipcApi.on("download-paused", (event, arg) => {
228 if (arg) { 227 if (arg) {
229 this.progressStaus = "warning"; 228 this.progressStaus = "warning";
230 this.$alert("下载由于未知原因被中断!", "提示", { 229 this.$alert("下载由于未知原因被中断!", "提示", {
231 confirmButtonText: "重试", 230 confirmButtonText: "重试",
232 callback: action => { 231 callback: action => {
233 - ipcApi.send("satrt-download"); 232 + this.$ipcApi.send("satrt-download");
234 } 233 }
235 }); 234 });
236 } 235 }
237 }); 236 });
238 - ipcApi.on("download-done", (event, age) => { 237 + this.$ipcApi.on("download-done", (event, age) => {
239 this.filePath = age.filePath; 238 this.filePath = age.filePath;
240 this.progressStaus = "success"; 239 this.progressStaus = "success";
241 this.$alert("更新下载完成!", "提示", { 240 this.$alert("更新下载完成!", "提示", {
...@@ -256,12 +255,12 @@ export default { ...@@ -256,12 +255,12 @@ export default {
256 } 255 }
257 }, 256 },
258 destroyed() { 257 destroyed() {
259 - ipcApi.remove("confirm-message"); 258 + this.$ipcApi.remove("confirm-message");
260 - ipcApi.remove("download-done"); 259 + this.$ipcApi.remove("download-done");
261 - ipcApi.remove("download-paused"); 260 + this.$ipcApi.remove("download-paused");
262 - ipcApi.remove("confirm-download"); 261 + this.$ipcApi.remove("confirm-download");
263 - ipcApi.remove("download-progress"); 262 + this.$ipcApi.remove("download-progress");
264 - ipcApi.remove("download-error"); 263 + this.$ipcApi.remove("download-error");
265 } 264 }
266 }; 265 };
267 </script> 266 </script>
......
...@@ -35,49 +35,51 @@ ...@@ -35,49 +35,51 @@
35 </template> 35 </template>
36 36
37 <script> 37 <script>
38 - export default { 38 +export default {
39 - data () { 39 + data() {
40 return { 40 return {
41 - electron: process.versions.electron, 41 + electron: process.versions.electron || "浏览器环境",
42 name: this.$route.name, 42 name: this.$route.name,
43 - node: process.versions.node, 43 + node: process.versions.node || "浏览器环境",
44 path: this.$route.path, 44 path: this.$route.path,
45 - platform: require('os').platform(), 45 + platform: require("os").platform(),
46 - arch:require('os').arch(), 46 + arch: require("os").arch(),
47 - vue: require('vue/package.json').version 47 + vue: require("vue/package.json").version
48 - } 48 + };
49 }, 49 },
50 - mounted(){ 50 + mounted() {
51 - console.log(this.$route) 51 + console.log(this.$route);
52 - }
53 } 52 }
53 +};
54 </script> 54 </script>
55 55
56 <style scoped> 56 <style scoped>
57 - .title { 57 +.title {
58 color: #888; 58 color: #888;
59 font-size: 18px; 59 font-size: 18px;
60 font-weight: initial; 60 font-weight: initial;
61 - letter-spacing: .25px; 61 + letter-spacing: 0.25px;
62 margin-top: 10px; 62 margin-top: 10px;
63 - } 63 +}
64 64
65 - .items { margin-top: 8px; } 65 +.items {
66 + margin-top: 8px;
67 +}
66 68
67 - .item { 69 +.item {
68 display: flex; 70 display: flex;
69 align-items: center; 71 align-items: center;
70 margin-bottom: 6px; 72 margin-bottom: 6px;
71 line-height: 24px; 73 line-height: 24px;
72 - } 74 +}
73 75
74 - .item .name { 76 +.item .name {
75 color: #6a6a6a; 77 color: #6a6a6a;
76 margin-right: 6px; 78 margin-right: 6px;
77 - } 79 +}
78 80
79 - .item .value { 81 +.item .value {
80 color: #35495e; 82 color: #35495e;
81 font-weight: bold; 83 font-weight: bold;
82 - } 84 +}
83 </style> 85 </style>
......
1 <!-- --> 1 <!-- -->
2 <template> 2 <template>
3 - <div class="window-title" v-if="!IsUseSysTitle&&isMac"> 3 + <div class="window-title" v-if="!IsUseSysTitle&&isMac&&!IsWeb">
4 <!-- 软件logo预留位置 --> 4 <!-- 软件logo预留位置 -->
5 <div style="-webkit-app-region: drag;" class="logo"> 5 <div style="-webkit-app-region: drag;" class="logo">
6 <svg-icon icon-class="electron-logo"></svg-icon> 6 <svg-icon icon-class="electron-logo"></svg-icon>
...@@ -25,32 +25,35 @@ ...@@ -25,32 +25,35 @@
25 </template> 25 </template>
26 26
27 <script> 27 <script>
28 -import ipcApi from "@/utils/ipcRenderer";
29 export default { 28 export default {
30 data: () => ({ 29 data: () => ({
31 mix: false, 30 mix: false,
32 IsUseSysTitle: false, 31 IsUseSysTitle: false,
33 - isMac:process.platform !== 'darwin' 32 + isMac: process.platform !== "darwin",
33 + IsWeb: process.env.IS_WEB
34 }), 34 }),
35 35
36 components: {}, 36 components: {},
37 created() { 37 created() {
38 - ipcApi.send("IsUseSysTitle"); 38 + this.$ipcApi.send("IsUseSysTitle");
39 - ipcApi.on("CisUseSysTitle", (event, arg) => (this.IsUseSysTitle = arg)); 39 + this.$ipcApi.on(
40 + "CisUseSysTitle",
41 + (event, arg) => (this.IsUseSysTitle = arg)
42 + );
40 }, 43 },
41 44
42 mounted() {}, 45 mounted() {},
43 46
44 methods: { 47 methods: {
45 Mini() { 48 Mini() {
46 - ipcApi.send("windows-mini"); 49 + this.$ipcApi.send("windows-mini");
47 }, 50 },
48 MixOrReduction() { 51 MixOrReduction() {
49 - ipcApi.send("window-max"); 52 + this.$ipcApi.send("window-max");
50 - ipcApi.on("window-confirm", (event, arg) => (this.mix = arg)); 53 + this.$ipcApi.on("window-confirm", (event, arg) => (this.mix = arg));
51 }, 54 },
52 Close() { 55 Close() {
53 - ipcApi.send("window-close"); 56 + this.$ipcApi.send("window-close");
54 } 57 }
55 } 58 }
56 }; 59 };
...@@ -69,7 +72,7 @@ export default { ...@@ -69,7 +72,7 @@ export default {
69 .title { 72 .title {
70 text-align: center; 73 text-align: center;
71 } 74 }
72 - .logo{ 75 + .logo {
73 margin-left: 20px; 76 margin-left: 20px;
74 } 77 }
75 .controls-container { 78 .controls-container {
......
...@@ -3,8 +3,6 @@ import Vue from 'vue' ...@@ -3,8 +3,6 @@ import Vue from 'vue'
3 import App from './App' 3 import App from './App'
4 import router from './router' 4 import router from './router'
5 import store from './store' 5 import store from './store'
6 -// 导入数据操作库
7 -import db from './api/operationalData'
8 // 引用element 6 // 引用element
9 import ElementUI from 'element-ui' 7 import ElementUI from 'element-ui'
10 import 'element-ui/lib/theme-chalk/index.css' 8 import 'element-ui/lib/theme-chalk/index.css'
...@@ -14,14 +12,18 @@ import './error' ...@@ -14,14 +12,18 @@ import './error'
14 import './icons' 12 import './icons'
15 import '@/styles/index.scss' 13 import '@/styles/index.scss'
16 14
17 -if (!require('../../config').IsUseSysTitle) require('@/styles/custom-title.scss') 15 +if (!process.env.IS_WEB) {
18 - 16 + Vue.use(require('vue-electron'))
19 -if (!process.env.IS_WEB) Vue.use(require('vue-electron')) 17 + if (!require('../../config').IsUseSysTitle) {
18 + require('@/styles/custom-title.scss')
19 + }
20 + // 当处于electron状态下才引用db
21 + Vue.prototype.$db = require('./api/operationalData').default
22 + Vue.prototype.$ipcApi = require('./utils/ipcRenderer').default
23 +}
20 24
21 Vue.use(ElementUI) 25 Vue.use(ElementUI)
22 26
23 -Vue.prototype.$db = db
24 -
25 Vue.config.productionTip = false 27 Vue.config.productionTip = false
26 /* eslint-disable no-new */ 28 /* eslint-disable no-new */
27 const vue = new Vue({ 29 const vue = new Vue({
......