-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
121 lines (107 loc) · 3.42 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
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
/**
* External dependencies
*/
const path = require('path');
const {
camelCaseDash,
} = require('@wordpress/dependency-extraction-webpack-plugin/lib/util');
/**
* Internal dependencies
*/
const { dependencies } = require('./package');
const packagesConfig = require('./packages/dev-tools/js/webpack/packages');
const exportDefaultPackages = [];
module.exports = (env, argv) => {
if (!argv) {
return require(path.resolve(
process.cwd(),
'packages/dev-cypress/js/webpack.config.js'
));
}
const BLOCKERA_NAMESPACE = '@blockera/';
const blockeraPackages = Object.keys(dependencies)
.filter((packageName) => packageName.startsWith(BLOCKERA_NAMESPACE))
.map((packageName) => packageName.replace(BLOCKERA_NAMESPACE, ''));
const blockeraPackagesVersion = Object.fromEntries(
blockeraPackages.map((packageName) => {
let parentDirectory = '';
let name = packageName;
if (-1 !== packageName.indexOf('blocks-')) {
parentDirectory = 'blocks/';
name = name.split('blocks-')[1];
}
const {
version,
} = require(`./packages/${parentDirectory}${name}/package.json`);
return [packageName, version.replace(/\./g, '_')];
})
);
const blockeraEntries = blockeraPackages.reduce((memo, packageName) => {
// Exclude dev packages.
if (-1 !== packageName.indexOf('dev-')) {
return memo;
}
if (!blockeraPackagesVersion[packageName]) {
return memo;
}
let parentDirectory = '';
let _packageName = packageName;
if (-1 !== packageName.indexOf('blocks-')) {
parentDirectory = 'blocks/';
_packageName = _packageName.split('blocks-')[1];
}
const version = blockeraPackagesVersion[packageName];
let name = packageName.startsWith('blockera')
? camelCaseDash(packageName + '_' + version)
: camelCaseDash('blockera-' + packageName + '_' + version);
if ('icons' === packageName) {
name = packageName.startsWith('blockera')
? camelCaseDash(packageName)
: camelCaseDash('blockera-' + packageName);
}
return {
...memo,
[packageName]: {
import: `./packages/${parentDirectory}${_packageName}`,
library: {
name,
type: 'var',
export: exportDefaultPackages.includes(packageName)
? 'default'
: undefined,
},
},
};
}, {});
return packagesConfig(env, {
...argv,
entry: blockeraEntries,
devtoolNamespace: 'blockera',
mode: argv?.mode || 'production',
externals: {
// Externalize the local packages.
'@blockera/icons': 'blockeraIcons',
'@blockera/env': 'blockeraEnv_' + blockeraPackagesVersion.env,
'@blockera/telemetry':
'blockeraTelemetry_' + blockeraPackagesVersion.telemetry,
'@blockera/storage':
'blockeraStorage_' + blockeraPackagesVersion.storage,
'@blockera/data': 'blockeraData_' + blockeraPackagesVersion.data,
'@blockera/utils': 'blockeraUtils_' + blockeraPackagesVersion.utils,
'@blockera/editor':
'blockeraEditor_' + blockeraPackagesVersion.editor,
'@blockera/core-blocks':
'blockeraBlocksCore_' + blockeraPackagesVersion['blocks-core'],
'@blockera/controls':
'blockeraControls_' + blockeraPackagesVersion.controls,
'@blockera/bootstrap':
'blockeraBootstrap_' + blockeraPackagesVersion.bootstrap,
'@blockera/wordpress':
'blockeraWordpress_' + blockeraPackagesVersion.wordpress,
'@blockera/classnames':
'blockeraClassnames_' + blockeraPackagesVersion.classnames,
'@blockera/data-editor':
'blockeraDataEditor_' + blockeraPackagesVersion['data-editor'],
},
});
};