UNPKG

1.08 kBJavaScriptView Raw
1module.exports = class WebpackUtils {
2 constructor(api) {
3 this.api = api
4 }
5
6 get envs() {
7 const envs = {}
8 // Collect variables starting with `POI_APP_` from `process.env`
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 PUBLIC_URL: this.api.config.output.publicUrl
18 })
19
20 return envs
21 }
22
23 get constants() {
24 return Object.assign({}, this.api.config.constants)
25 }
26
27 get CopyPlugin() {
28 return require('copy-webpack-plugin')
29 }
30
31 addParallelSupport(rule) {
32 if (this.api.config.parallel) {
33 rule.use('thread-loader').loader(require.resolve('thread-loader'))
34 }
35
36 return this
37 }
38
39 addCacheSupport(rule, getCacheConfig) {
40 if (this.api.config.cache) {
41 rule
42 .use('cache-loader')
43 .loader(require.resolve('cache-loader'))
44 .options(getCacheConfig())
45 }
46
47 return this
48 }
49}