1 | module.exports = class WebpackUtils {
|
2 | constructor(api) {
|
3 | this.api = api
|
4 | }
|
5 |
|
6 | get envs() {
|
7 | const envs = {}
|
8 |
|
9 | for (const name of Object.keys(process.env)) {
|
10 | if (name.startsWith('POI_APP_')) {
|
11 | envs[name] = process.env[name]
|
12 | }
|
13 | }
|
14 |
|
15 | Object.assign(envs, this.api.config.envs, {
|
16 | NODE_ENV: this.api.mode === 'production' ? 'production' : 'development'
|
17 | })
|
18 |
|
19 | return envs
|
20 | }
|
21 |
|
22 | get constants() {
|
23 | return Object.assign({}, this.api.config.constants, {
|
24 | __PUBLIC_URL__: JSON.stringify(this.api.config.output.publicUrl)
|
25 | })
|
26 | }
|
27 |
|
28 | get CopyPlugin() {
|
29 | return require('copy-webpack-plugin')
|
30 | }
|
31 |
|
32 | addParallelSupport(rule) {
|
33 | if (this.api.config.parallel) {
|
34 | rule.use('thread-loader').loader('thread-loader')
|
35 | }
|
36 |
|
37 | return this
|
38 | }
|
39 |
|
40 | addCacheSupport(rule, getCacheConfig) {
|
41 | if (this.api.config.cache) {
|
42 | rule
|
43 | .use('cache-loader')
|
44 | .loader('cache-loader')
|
45 | .options(getCacheConfig())
|
46 | }
|
47 |
|
48 | return this
|
49 | }
|
50 | }
|