forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
131 lines (106 loc) · 3.27 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const webpack = require('webpack')
const WebpackChain = require('webpack-chain')
const WebpackProgress = require('../plugin.progress')
const ExpressionDependency = require('./plugin.expression-dependency')
const parseBuildEnv = require('../../helpers/parse-build-env')
const appPaths = require('../../app-paths')
module.exports = function (cfg, configName) {
const { dependencies:appDeps = {} } = require(appPaths.resolve.app('package.json'))
const { dependencies:cliDeps = {} } = require(appPaths.resolve.cli('package.json'))
const chain = new WebpackChain()
const resolveModules = [
'node_modules',
appPaths.resolve.app('node_modules'),
appPaths.resolve.cli('node_modules')
]
chain.target('electron-main')
chain.mode(cfg.ctx.dev ? 'development' : 'production')
chain.node
.merge({
__dirname: cfg.ctx.dev,
__filename: cfg.ctx.dev
})
chain.entry('electron-main')
.add(appPaths.resolve.app(
cfg.ctx.dev ? cfg.sourceFiles.electronMainDev : cfg.sourceFiles.electronMainProd
))
chain.output
.filename('electron-main.js')
.libraryTarget('commonjs2')
.path(
cfg.ctx.dev
? appPaths.resolve.app('.quasar/electron')
: cfg.build.distDir
)
chain.externals([
...Object.keys(cliDeps),
...Object.keys(appDeps)
])
chain.plugin('expression-dependency')
.use(ExpressionDependency)
if (cfg.build.transpile === true) {
chain.module.rule('babel')
.test(/\.js$/)
.exclude
.add(/node_modules/)
.end()
.use('babel-loader')
.loader('babel-loader')
.options({
extends: appPaths.resolve.app('babel.config.js')
})
}
chain.module.rule('node')
.test(/\.node$/)
.use('node-loader')
.loader('node-loader')
chain.resolve.modules
.merge(resolveModules)
chain.resolve.extensions
.merge([ '.js', '.json', '.node' ])
chain.resolveLoader.modules
.merge(resolveModules)
chain.optimization
.noEmitOnErrors(true)
if (cfg.build.showProgress) {
chain.plugin('progress')
.use(WebpackProgress, [{ name: configName }])
}
const env = Object.assign({}, cfg.build.env, {
QUASAR_NODE_INTEGRATION: cfg.electron.nodeIntegration === true
})
chain.plugin('define')
.use(webpack.DefinePlugin, [
parseBuildEnv(env, cfg.__rootDefines)
])
if (cfg.ctx.prod) {
if (cfg.build.minify) {
const TerserPlugin = require('terser-webpack-plugin')
chain.optimization
.minimizer('js')
.use(TerserPlugin, [{
terserOptions: cfg.build.uglifyOptions,
cache: true,
parallel: true,
sourceMap: cfg.build.sourceMap
}])
}
const ElectronPackageJson = require('./plugin.electron-package-json')
// write package.json file
chain.plugin('package-json')
.use(ElectronPackageJson, [ cfg ])
const patterns = [
appPaths.resolve.app('.npmrc'),
appPaths.resolve.app('.yarnrc'),
appPaths.resolve.electron('main-process/electron-preload.js')
].map(filename => ({
from: filename,
to: '.',
noErrorOnMissing: true
}))
const CopyWebpackPlugin = require('copy-webpack-plugin')
chain.plugin('copy-webpack')
.use(CopyWebpackPlugin, [{ patterns }])
}
return chain
}