umbrella22

剔除冗余代码

...@@ -11,7 +11,6 @@ const Multispinner = require('multispinner') ...@@ -11,7 +11,6 @@ const Multispinner = require('multispinner')
11 11
12 const mainConfig = require('./webpack.main.config') 12 const mainConfig = require('./webpack.main.config')
13 const rendererConfig = require('./webpack.renderer.config') 13 const rendererConfig = require('./webpack.renderer.config')
14 -const webConfig = require('./webpack.web.config')
15 14
16 const doneLog = chalk.bgGreen.white(' DONE ') + ' ' 15 const doneLog = chalk.bgGreen.white(' DONE ') + ' '
17 const errorLog = chalk.bgRed.white(' ERROR ') + ' ' 16 const errorLog = chalk.bgRed.white(' ERROR ') + ' '
...@@ -99,8 +98,8 @@ function pack (config) { ...@@ -99,8 +98,8 @@ function pack (config) {
99 98
100 function web () { 99 function web () {
101 del.sync(['dist/web/*', '!.gitkeep']) 100 del.sync(['dist/web/*', '!.gitkeep'])
102 - webConfig.mode = 'production' 101 + rendererConfig.mode = 'production'
103 - webpack(webConfig, (err, stats) => { 102 + webpack(rendererConfig, (err, stats) => {
104 if (err || stats.hasErrors()) console.log(err) 103 if (err || stats.hasErrors()) console.log(err)
105 104
106 console.log(stats.toString({ 105 console.log(stats.toString({
......
1 'use strict' 1 'use strict'
2 2
3 process.env.NODE_ENV = 'development' 3 process.env.NODE_ENV = 'development'
4 +
4 const chalk = require('chalk') 5 const chalk = require('chalk')
5 const electron = require('electron') 6 const electron = require('electron')
6 const path = require('path') 7 const path = require('path')
......
...@@ -8,10 +8,6 @@ const webpack = require('webpack') ...@@ -8,10 +8,6 @@ const webpack = require('webpack')
8 const MinifyPlugin = require("babel-minify-webpack-plugin"); 8 const MinifyPlugin = require("babel-minify-webpack-plugin");
9 const config = require('../config') 9 const config = require('../config')
10 10
11 -// const os = require('os')
12 -// const HappyPack = require('happypack')
13 -// const HappyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length > 4 ? 4 : os.cpus().length })
14 -
15 function resolve(dir) { 11 function resolve(dir) {
16 return path.join(__dirname, '..', dir) 12 return path.join(__dirname, '..', dir)
17 } 13 }
...@@ -43,7 +39,7 @@ let mainConfig = { ...@@ -43,7 +39,7 @@ let mainConfig = {
43 // }, 39 // },
44 { 40 {
45 test: /\.ts$/, 41 test: /\.ts$/,
46 - use: [{ 42 + use: ['thread-loader',{
47 loader: 'babel-loader', 43 loader: 'babel-loader',
48 options: { 44 options: {
49 cacheDirectory: true 45 cacheDirectory: true
...@@ -68,16 +64,6 @@ let mainConfig = { ...@@ -68,16 +64,6 @@ let mainConfig = {
68 }, 64 },
69 plugins: [ 65 plugins: [
70 new webpack.NoEmitOnErrorsPlugin(), 66 new webpack.NoEmitOnErrorsPlugin(),
71 - // new HappyPack({
72 - // id: "MainHappyBabel",
73 - // loaders: [{
74 - // loader: 'babel-loader',
75 - // options: {
76 - // cacheDirectory: true
77 - // }
78 - // }],
79 - // threadPool: HappyThreadPool
80 - // })
81 ], 67 ],
82 resolve: { 68 resolve: {
83 alias: { 69 alias: {
......
1 -'use strict'
2 -
3 -process.env.BABEL_ENV = 'web'
4 -
5 -const os = require('os')
6 -const path = require('path')
7 -const webpack = require('webpack')
8 -
9 -const MinifyPlugin = require("babel-minify-webpack-plugin");
10 -const CopyWebpackPlugin = require('copy-webpack-plugin')
11 -const MiniCssExtractPlugin = require('mini-css-extract-plugin')
12 -const HtmlWebpackPlugin = require('html-webpack-plugin')
13 -const TerserPlugin = require('terser-webpack-plugin');
14 -const { VueLoaderPlugin } = require('vue-loader')
15 -const HappyPack = require('happypack')
16 -const HappyThreadPool = HappyPack.ThreadPool({ size: os.cpus().length > 4 ? 4 : os.cpus().length })
17 -
18 -function resolve(dir) {
19 - return path.join(__dirname, '..', dir)
20 -}
21 -
22 -let webConfig = {
23 - devtool: '#cheap-module-eval-source-map',
24 - entry: {
25 - web: resolve('src/renderer/main.js')
26 - },
27 - module: {
28 - rules: [
29 - // {
30 - // test: /\.(js|vue)$/,
31 - // enforce: 'pre',
32 - // exclude: /node_modules/,
33 - // use: {
34 - // loader: 'eslint-loader',
35 - // options: {
36 - // formatter: require('eslint-friendly-formatter')
37 - // }
38 - // }
39 - // },
40 - {
41 - test: /\.scss$/,
42 - use: ['vue-style-loader',
43 - {
44 - loader: 'css-loader',
45 - options: {
46 - esModule: false
47 - }
48 - },
49 - 'sass-loader']
50 - },
51 - {
52 - test: /\.sass$/,
53 - use: ['vue-style-loader',
54 - {
55 - loader: 'css-loader',
56 - options: {
57 - esModule: false
58 - }
59 - }, 'sass-loader?indentedSyntax']
60 - },
61 - {
62 - test: /\.less$/,
63 - use: ['vue-style-loader',
64 - {
65 - loader: 'css-loader',
66 - options: {
67 - esModule: false
68 - }
69 - }, 'less-loader']
70 - },
71 - {
72 - test: /\.css$/,
73 - use: ['vue-style-loader',
74 - {
75 - loader: 'css-loader',
76 - options: {
77 - esModule: false
78 - }
79 - }]
80 - },
81 - {
82 - test: /\.html$/,
83 - use: 'vue-html-loader'
84 - },
85 - {
86 - test: /\.js$/,
87 - use: 'happypack/loader?id=HappyRendererBabel',
88 - include: [resolve('src/renderer')],
89 - exclude: /node_modules/
90 - },
91 - {
92 - test: /\.vue$/,
93 - use: {
94 - loader: 'vue-loader',
95 - options: {
96 - loader: 'vue-loader',
97 - options: {
98 - cacheDirectory: 'node_modules/.cache/vue-loader',
99 - cacheIdentifier: '7270960a',
100 - }
101 - }
102 - }
103 - },
104 - {
105 - test: /\.svg$/,
106 - loader: 'svg-sprite-loader',
107 - include: [resolve('src/renderer/icons')],
108 - options: {
109 - symbolId: 'icon-[name]'
110 - }
111 - },
112 - {
113 - test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
114 - exclude: [resolve('src/renderer/icons')],
115 - use: {
116 - loader: 'url-loader',
117 - query: {
118 - esModule: false,
119 - limit: 10000,
120 - name: 'imgs/[name].[ext]'
121 - }
122 - },
123 - },
124 - {
125 - test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
126 - use: {
127 - loader: 'url-loader',
128 - query: {
129 - esModule: false,
130 - limit: 10000,
131 - name: 'fonts/[name].[ext]'
132 - }
133 - }
134 - }
135 - ]
136 - },
137 - plugins: [
138 - new VueLoaderPlugin(),
139 - new MiniCssExtractPlugin({ filename: 'styles.css' }),
140 - new HtmlWebpackPlugin({
141 - filename: 'index.html',
142 - template: path.resolve(__dirname, '../src/index.ejs'),
143 - minify: {
144 - collapseWhitespace: true,
145 - removeAttributeQuotes: true,
146 - removeComments: true
147 - },
148 - nodeModules: false
149 - }),
150 - new webpack.DefinePlugin({
151 - 'process.env.IS_WEB': 'true'
152 - }),
153 - new webpack.HotModuleReplacementPlugin(),
154 - new webpack.NoEmitOnErrorsPlugin(),
155 - new HappyPack({
156 - id: 'HappyRendererBabel',
157 - loaders: [{
158 - loader: 'babel-loader',
159 - options: {
160 - cacheDirectory: true
161 - }
162 - }],
163 - threadPool: HappyThreadPool
164 - }),
165 - ],
166 - output: {
167 - filename: '[name].js',
168 - path: path.join(__dirname, '../dist/web')
169 - },
170 - resolve: {
171 - alias: {
172 - '@': path.join(__dirname, '../src/renderer'),
173 - 'vue$': 'vue/dist/vue.esm.js'
174 - },
175 - extensions: ['.js', '.vue', '.json', '.css']
176 - },
177 - target: 'web'
178 -}
179 -
180 -/**
181 - * Adjust webConfig for production settings
182 - */
183 -if (process.env.NODE_ENV === 'production') {
184 - webConfig.devtool = ''
185 -
186 - webConfig.plugins.push(
187 - new MinifyPlugin(),
188 - new CopyWebpackPlugin({
189 - patterns: [
190 - {
191 - from: path.join(__dirname, '../static'),
192 - to: path.join(__dirname, '../dist/electron/static'),
193 - globOptions: {
194 - ignore: ['.*']
195 - }
196 - }
197 - ]
198 - }),
199 - new webpack.DefinePlugin({
200 - 'process.env.NODE_ENV': '"production"'
201 - }),
202 - new webpack.LoaderOptionsPlugin({
203 - minimize: true
204 - })
205 - )
206 - webConfig.optimization = {
207 - splitChunks: {
208 - chunks: "async",
209 - cacheGroups: {
210 - vendor: { // 将第三方模块提取出来
211 - minSize: 30000,
212 - minChunks: 1,
213 - test: /node_modules/,
214 - chunks: 'initial',
215 - name: 'vendor',
216 - priority: 1
217 - },
218 - commons: {
219 - test: /[\\/]src[\\/]common[\\/]/,
220 - name: 'commons',
221 - minSize: 30000,
222 - minChunks: 3,
223 - chunks: 'initial',
224 - priority: -1,
225 - reuseExistingChunk: true // 这个配置允许我们使用已经存在的代码块
226 - }
227 - }
228 - },
229 - runtimeChunk: { name: 'runtime' },
230 - minimizer: [
231 - new TerserPlugin({
232 - test: /\.js(\?.*)?$/i,
233 - extractComments: false,
234 - cache: false,
235 - sourceMap: false,
236 - terserOptions: {
237 - warnings: false,
238 - compress: {
239 - hoist_funs: false,
240 - hoist_props: false,
241 - hoist_vars: false,
242 - inline: false,
243 - loops: false,
244 - dead_code: true,
245 - booleans: true,
246 - if_return: true,
247 - warnings: false,
248 - drop_console: true,
249 - drop_debugger: true,
250 - pure_funcs: ['console.log']
251 - },
252 - output: {
253 - comments: false,
254 - },
255 - }
256 - })]
257 - }
258 -}
259 -
260 -module.exports = webConfig