-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
68 lines (61 loc) · 1.69 KB
/
webpack.config.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
const defaultConfig = require('@wordpress/scripts/config/webpack.config')
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin')
const fs = require('fs')
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin
const isProduction = process.env.NODE_ENV === 'production'
const configOverwrite = isProduction
? {}
: {
compilerOptions: {
strict: false,
noUnusedLocals: false,
noUnusedParameters: false,
},
}
const tsChecker = new ForkTsCheckerWebpackPlugin({
typescript: {
diagnosticOptions: { semantic: true, syntactic: true },
configOverwrite,
},
})
const initialEntrypoints = {
'inseri-core': {
import: './src/globalScript',
library: {
name: 'inseri',
type: 'window',
},
},
'inseri-core-editor': {
import: './src/globalScript/editor',
library: {
name: 'inseriEditor',
type: 'window',
},
},
}
const blockEntrypoints = fs.readdirSync('./src/blocks').reduce((accumulator, item) => {
const worker = fs.existsSync(`./src/blocks/${item}/worker.ts`) ? { [`blocks/${item}/worker`]: `./src/blocks/${item}/worker` } : {}
return {
...accumulator,
[`blocks/${item}/index`]: `./src/blocks/${item}`,
[`blocks/${item}/hydration`]: `./src/blocks/${item}/hydration`,
...worker,
}
}, initialEntrypoints)
if (process.env.DISABLE_MINIMIZE === 'true') {
defaultConfig.optimization.minimizer = []
}
module.exports = {
...defaultConfig,
entry: { ...blockEntrypoints },
plugins: [
...defaultConfig.plugins,
tsChecker,
new BundleAnalyzerPlugin({ analyzerMode: process.env.STATS || 'disabled' }),
],
externals: [
{ '@inseri/lighthouse': 'window.inseri.lighthouse' },
{ '@inseri/utils': 'window.inseri.utils' },
],
}