@machtwatch/react-script 1.2.11-alpha.32 → 1.2.11-alpha.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/config/babel/babel-custom-loader.js +65 -61
- package/config/jest/createJestConfig.js +4 -1
- package/config/jest/jest-setup.js +0 -3
- package/package.json +10 -7
- package/scripts/build.js +14 -4
- package/scripts/lib/webpackHotDevClient.js +25 -25
- package/scripts/start.js +19 -7
- package/scripts/test.js +29 -18
- package/scripts/utils/clean.js +1 -3
- package/scripts/webpack.config.js +167 -179
|
@@ -1,66 +1,70 @@
|
|
|
1
1
|
module.exports = () => ({
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
],
|
|
20
|
-
require('@babel/preset-react'),
|
|
21
|
-
|
|
2
|
+
customOptions({ transform_runtime, isClient, ...loader }) {
|
|
3
|
+
return {
|
|
4
|
+
loader,
|
|
5
|
+
custom: { ...transform_runtime, isClient }
|
|
6
|
+
};
|
|
7
|
+
},
|
|
8
|
+
config(cfg) {
|
|
9
|
+
return {
|
|
10
|
+
...cfg.options,
|
|
11
|
+
presets: [
|
|
12
|
+
[
|
|
13
|
+
require('@babel/preset-env'),
|
|
14
|
+
{
|
|
15
|
+
modules: false,
|
|
16
|
+
useBuiltIns: 'usage',
|
|
17
|
+
corejs: '3.22'
|
|
18
|
+
}
|
|
22
19
|
],
|
|
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
|
-
|
|
20
|
+
require('@babel/preset-react'),
|
|
21
|
+
|
|
22
|
+
],
|
|
23
|
+
plugins: [
|
|
24
|
+
require('@babel/plugin-transform-runtime'),
|
|
25
|
+
require('@babel/plugin-proposal-function-bind'),
|
|
26
|
+
require('@babel/plugin-proposal-export-default-from'),
|
|
27
|
+
require('@babel/plugin-proposal-export-namespace-from'),
|
|
28
|
+
require('@babel/plugin-proposal-throw-expressions'),
|
|
29
|
+
require('@babel/plugin-syntax-dynamic-import'),
|
|
30
|
+
require('@babel/plugin-proposal-json-strings'),
|
|
31
|
+
require('@loadable/babel-plugin'),
|
|
32
|
+
[require('babel-plugin-transform-imports'), {
|
|
33
|
+
'@machtwatch/react-ui': {
|
|
34
|
+
transform: '@machtwatch/react-ui/lib/${member}',
|
|
35
|
+
preventFullImport: true
|
|
36
|
+
}
|
|
37
|
+
}],
|
|
38
|
+
[require('@babel/plugin-proposal-decorators'), {
|
|
39
|
+
legacy: true
|
|
40
|
+
}],
|
|
41
|
+
[require('@babel/plugin-proposal-optional-chaining'), {
|
|
42
|
+
loose: true
|
|
43
|
+
}],
|
|
44
|
+
[require('@babel/plugin-proposal-class-properties'), {
|
|
45
|
+
loose: true
|
|
46
|
+
}],
|
|
47
|
+
[require('@babel/plugin-proposal-private-methods'), { loose: true }],
|
|
48
|
+
[require('@babel/plugin-proposal-private-property-in-object'), { loose: true }],
|
|
49
|
+
[require('babel-plugin-add-module-exports'), {
|
|
50
|
+
addDefaultProperty: true
|
|
51
|
+
}],
|
|
52
|
+
...(cfg.options.isClient && !cfg.options.compact ? [
|
|
53
|
+
require.resolve('react-refresh/babel')
|
|
54
|
+
] : [
|
|
52
55
|
...(cfg.options.compact ? [
|
|
53
56
|
require('@babel/plugin-transform-react-inline-elements'),
|
|
54
57
|
require('@babel/plugin-transform-react-constant-elements')
|
|
55
|
-
] : [])
|
|
56
|
-
|
|
57
|
-
]
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
}
|
|
58
|
+
] : [])
|
|
59
|
+
]),
|
|
60
|
+
...(cfg.options.plugins || [])
|
|
61
|
+
],
|
|
62
|
+
};
|
|
63
|
+
},
|
|
64
|
+
result(result) {
|
|
65
|
+
return {
|
|
66
|
+
...result,
|
|
67
|
+
code: `${result.code} \n// Generated by babel-custom-loader`
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
});
|
|
@@ -4,7 +4,7 @@ const path = require('path');
|
|
|
4
4
|
const fs = require('fs');
|
|
5
5
|
const merge = require('deepmerge');
|
|
6
6
|
|
|
7
|
-
module.exports = (resolve, rootDir, srcRoots) => {
|
|
7
|
+
module.exports = (resolve, rootDir, srcRoots, appConfig) => {
|
|
8
8
|
const toRelRootDir = f => '<rootDir>/' + path.relative(rootDir || '', f);
|
|
9
9
|
const extendedPath = path.join(process.cwd(), 'extended-jest.config.js');
|
|
10
10
|
|
|
@@ -26,6 +26,9 @@ module.exports = (resolve, rootDir, srcRoots) => {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
const config = {
|
|
29
|
+
globals: {
|
|
30
|
+
CONFIG: appConfig && (appConfig.globals || appConfig),
|
|
31
|
+
},
|
|
29
32
|
setupFiles: [resolve('scripts/utils/polyfills.js')],
|
|
30
33
|
testMatch: [
|
|
31
34
|
"<rootDir>/src/shared/**/*.(spec|test).{js,jsx,mjs}"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@machtwatch/react-script",
|
|
3
|
-
"version": "1.2.11-alpha.
|
|
3
|
+
"version": "1.2.11-alpha.34",
|
|
4
4
|
"description": "Machtwatch React script",
|
|
5
5
|
"author": "Danny Reza Miloen <danny@machtwatch.co.id>",
|
|
6
6
|
"contributors": [],
|
|
@@ -51,9 +51,10 @@
|
|
|
51
51
|
"@babel/preset-react": "^7.17.12",
|
|
52
52
|
"@loadable/babel-plugin": "^5.13.2",
|
|
53
53
|
"@loadable/webpack-plugin": "^5.15.2",
|
|
54
|
+
"@pmmmwh/react-refresh-webpack-plugin": "0.6.2",
|
|
54
55
|
"@svgr/webpack": "^6.2.1",
|
|
55
56
|
"@testing-library/jest-dom": "^5.12.0",
|
|
56
|
-
"@testing-library/react": "
|
|
57
|
+
"@testing-library/react": "13.0.0",
|
|
57
58
|
"assets-webpack-plugin": "7.1.1",
|
|
58
59
|
"autoprefixer": "^10.4.20",
|
|
59
60
|
"babel-jest": "^26.3.0",
|
|
@@ -64,7 +65,6 @@
|
|
|
64
65
|
"browser-sync": "^2.26.7",
|
|
65
66
|
"child_process": "^1.0.2",
|
|
66
67
|
"compression-webpack-plugin": "^10.0.0",
|
|
67
|
-
"config": "^3.3.9",
|
|
68
68
|
"core-js": "^3.23.3",
|
|
69
69
|
"css-loader": "^7.1.2",
|
|
70
70
|
"css-minimizer-webpack-plugin": "^4.0.0",
|
|
@@ -80,8 +80,6 @@
|
|
|
80
80
|
"imagemin-webp-webpack-plugin": "^3.3.6",
|
|
81
81
|
"intersection-observer": "^0.5.1",
|
|
82
82
|
"jest": "^26.4.2",
|
|
83
|
-
"less": "^4.2.1",
|
|
84
|
-
"less-loader": "^12.2.0",
|
|
85
83
|
"mini-css-extract-plugin": "^2.6.1",
|
|
86
84
|
"mkdirp": "^0.5.1",
|
|
87
85
|
"null-loader": "^4.0.1",
|
|
@@ -90,11 +88,16 @@
|
|
|
90
88
|
"postcss-flexbugs-fixes": "^5.0.2",
|
|
91
89
|
"postcss-import": "^14.1.0",
|
|
92
90
|
"postcss-loader": "^8.1.1",
|
|
91
|
+
"postcss-nested": "^6.0.1",
|
|
93
92
|
"postcss-preset-env": "^7.7.1",
|
|
93
|
+
"process": "0.11.10",
|
|
94
94
|
"promise": "^8.0.2",
|
|
95
95
|
"purgecss-webpack-plugin": "^4.1.3",
|
|
96
|
+
"react": "18.3.1",
|
|
96
97
|
"react-dev-utils": "^12.0.1",
|
|
97
|
-
"react-
|
|
98
|
+
"react-dom": "18.3.1",
|
|
99
|
+
"react-error-overlay": "6.0.11",
|
|
100
|
+
"react-refresh": "0.18.0",
|
|
98
101
|
"recluster": "^0.4.5",
|
|
99
102
|
"regenerator-runtime": "^0.13.3",
|
|
100
103
|
"rimraf": "^2.6.3",
|
|
@@ -103,7 +106,7 @@
|
|
|
103
106
|
"speed-measure-webpack-plugin": "^1.5.0",
|
|
104
107
|
"style-loader": "^4.0.0",
|
|
105
108
|
"stylelint": "^16.10.0",
|
|
106
|
-
"stylelint-config-recommended
|
|
109
|
+
"stylelint-config-recommended": "^14.0.1",
|
|
107
110
|
"stylelint-webpack-plugin": "^5.0.1",
|
|
108
111
|
"tailwindcss": "^3.4.17",
|
|
109
112
|
"terser": "^5.14.1",
|
package/scripts/build.js
CHANGED
|
@@ -5,14 +5,18 @@ const run = require('./utils/run');
|
|
|
5
5
|
const clean = require('./utils/clean');
|
|
6
6
|
const copy = require('./utils/copy');
|
|
7
7
|
const pkg = require('../package.json');
|
|
8
|
-
const
|
|
8
|
+
const paths = require('../config/paths');
|
|
9
|
+
const { createRequire } = require('module');
|
|
10
|
+
|
|
11
|
+
const requireApp = createRequire(`${paths.appPath}/package.json`);
|
|
12
|
+
const { loadConfig } = requireApp('c12');
|
|
9
13
|
|
|
10
14
|
/**
|
|
11
15
|
* Compiles the project from source files into a distributable
|
|
12
16
|
* format and copies it to the output (build) folder.
|
|
13
17
|
*/
|
|
14
18
|
|
|
15
|
-
function bundle() {
|
|
19
|
+
function bundle(webpackConfig) {
|
|
16
20
|
return new Promise((resolve, reject) => {
|
|
17
21
|
webpack(webpackConfig).run((err, stats) => {
|
|
18
22
|
if (err) {
|
|
@@ -27,9 +31,15 @@ function bundle() {
|
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
async function build() {
|
|
30
|
-
await
|
|
34
|
+
const { config } = await loadConfig({
|
|
35
|
+
cwd: paths.appPath,
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const webpackConfig = await require('./webpack.config')(config);
|
|
39
|
+
|
|
40
|
+
await run(clean, config);
|
|
31
41
|
await run(copy);
|
|
32
|
-
await run(bundle);
|
|
42
|
+
await run(bundle.bind(null, webpackConfig));
|
|
33
43
|
|
|
34
44
|
if (process.argv.includes('--docker')) {
|
|
35
45
|
cp.spawnSync('docker', ['build', '-t', pkg.name, '.'], { stdio: 'inherit' })
|
|
@@ -10,38 +10,38 @@ const {
|
|
|
10
10
|
stopReportingRuntimeErrors,
|
|
11
11
|
} = require('react-error-overlay');
|
|
12
12
|
|
|
13
|
-
setEditorHandler(errorLocation => {
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
// setEditorHandler(errorLocation => {
|
|
14
|
+
// const fileName = encodeURIComponent(errorLocation.fileName);
|
|
15
|
+
// const lineNumber = encodeURIComponent(errorLocation.lineNumber || 1);
|
|
16
|
+
//
|
|
17
|
+
// fetch(
|
|
18
|
+
// // Keep in sync with react-dev-utils/errorOverlayMiddleware
|
|
19
|
+
// `${launchEditorEndpoint}?fileName=${fileName}&lineNumber=${lineNumber}`,
|
|
20
|
+
// );
|
|
21
|
+
// });
|
|
16
22
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
reportBuildError(formatted.errors[0]);
|
|
31
|
-
},
|
|
32
|
-
clear() {
|
|
33
|
-
dismissBuildError();
|
|
34
|
-
},
|
|
35
|
-
});
|
|
23
|
+
// hotClient.useCustomOverlay({
|
|
24
|
+
// showProblems(type, errors) {
|
|
25
|
+
// const formatted = formatWebpackMessages({
|
|
26
|
+
// errors,
|
|
27
|
+
// warnings: [],
|
|
28
|
+
// });
|
|
29
|
+
//
|
|
30
|
+
// reportBuildError(formatted.errors[0]);
|
|
31
|
+
// },
|
|
32
|
+
// clear() {
|
|
33
|
+
// dismissBuildError();
|
|
34
|
+
// },
|
|
35
|
+
// });
|
|
36
36
|
|
|
37
37
|
hotClient.setOptionsAndConnect({
|
|
38
38
|
name: 'client',
|
|
39
39
|
reload: true,
|
|
40
40
|
});
|
|
41
41
|
|
|
42
|
-
startReportingRuntimeErrors({
|
|
43
|
-
|
|
44
|
-
});
|
|
42
|
+
// startReportingRuntimeErrors({
|
|
43
|
+
// filename: '/assets/client.js',
|
|
44
|
+
// });
|
|
45
45
|
|
|
46
46
|
if (module.hot) {
|
|
47
47
|
module.hot.dispose(stopReportingRuntimeErrors);
|
package/scripts/start.js
CHANGED
|
@@ -7,11 +7,13 @@ const webpackHotMiddleware = require('webpack-hot-middleware');
|
|
|
7
7
|
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
|
8
8
|
|
|
9
9
|
const paths = require('../config/paths');
|
|
10
|
-
|
|
10
|
+
|
|
11
11
|
const run = require('./utils/run');
|
|
12
12
|
const clean = require('./utils/clean');
|
|
13
|
+
const { createRequire } = require('module');
|
|
13
14
|
|
|
14
|
-
const
|
|
15
|
+
const requireApp = createRequire(`${paths.appPath}/package.json`);
|
|
16
|
+
const { loadConfig } = requireApp('c12');
|
|
15
17
|
|
|
16
18
|
const { format } = run;
|
|
17
19
|
|
|
@@ -69,12 +71,18 @@ async function start() {
|
|
|
69
71
|
return server;
|
|
70
72
|
}
|
|
71
73
|
|
|
74
|
+
const { config } = await loadConfig({
|
|
75
|
+
cwd: paths.appPath,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const webpackConfig = await require('./webpack.config')(config);
|
|
79
|
+
|
|
72
80
|
server = express();
|
|
73
81
|
server.use(errorOverlayMiddleware());
|
|
74
82
|
server.use(express.static(paths.appPublic));
|
|
75
83
|
|
|
76
84
|
// Configure client-side hot module replacement
|
|
77
|
-
const clientConfig = webpackConfig.find(
|
|
85
|
+
const clientConfig = webpackConfig.find(c => c.name === 'client');
|
|
78
86
|
|
|
79
87
|
clientConfig.entry.client = [path.resolve(`${__dirname}/lib/webpackHotDevClient`)]
|
|
80
88
|
.concat(clientConfig.entry.client)
|
|
@@ -109,7 +117,7 @@ async function start() {
|
|
|
109
117
|
);
|
|
110
118
|
|
|
111
119
|
// Configure compilation
|
|
112
|
-
await run(clean);
|
|
120
|
+
await run(clean, config);
|
|
113
121
|
|
|
114
122
|
const clientCompiler = webpack(clientConfig);
|
|
115
123
|
const serverCompiler = webpack(serverConfig);
|
|
@@ -187,12 +195,14 @@ async function start() {
|
|
|
187
195
|
checkForUpdate(true);
|
|
188
196
|
}
|
|
189
197
|
})
|
|
190
|
-
.catch(error => {
|
|
198
|
+
.catch(async error => {
|
|
191
199
|
if (['abort', 'fail'].includes(app.hot.status())) {
|
|
192
200
|
console.warn(`${hmrPrefix}Cannot apply update.`);
|
|
193
201
|
delete require.cache[require.resolve(`${paths.appBuild}/server`)];
|
|
194
202
|
// eslint-disable-next-line global-require, import/no-unresolved
|
|
195
|
-
|
|
203
|
+
const bundle = require(`${paths.appBuild}/server`);
|
|
204
|
+
const loaded = bundle instanceof Promise ? await bundle : bundle;
|
|
205
|
+
app = loaded.default;
|
|
196
206
|
console.warn(`${hmrPrefix}App has been reloaded.`);
|
|
197
207
|
} else {
|
|
198
208
|
console.warn(
|
|
@@ -223,7 +233,9 @@ async function start() {
|
|
|
223
233
|
|
|
224
234
|
// Load compiled src/server.js as a middleware
|
|
225
235
|
// eslint-disable-next-line global-require, import/no-unresolved
|
|
226
|
-
|
|
236
|
+
const bundle = require(`${paths.appBuild}/server`);
|
|
237
|
+
const loaded = bundle instanceof Promise ? await bundle : bundle;
|
|
238
|
+
app = loaded.default;
|
|
227
239
|
appPromiseIsResolved = true;
|
|
228
240
|
appPromiseResolve();
|
|
229
241
|
|
package/scripts/test.js
CHANGED
|
@@ -9,32 +9,43 @@ process.on('unhandledRejection', err => {
|
|
|
9
9
|
|
|
10
10
|
const jest = require('jest');
|
|
11
11
|
const path = require('path');
|
|
12
|
+
const { createRequire } = require('module');
|
|
12
13
|
|
|
13
14
|
const createJestConfig = require('../config/jest/createJestConfig');
|
|
14
15
|
const paths = require('../config/paths');
|
|
15
16
|
|
|
17
|
+
const requireApp = createRequire(`${paths.appPath}/package.json`);
|
|
18
|
+
const { loadConfig } = requireApp('c12');
|
|
19
|
+
|
|
16
20
|
require('../config/env');
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
async function start() {
|
|
23
|
+
const { config } = await loadConfig({ cwd: paths.appPath });
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
let argv = process.argv.slice(2);
|
|
26
|
+
|
|
27
|
+
if (argv.indexOf('--coverage') === -1 && argv.indexOf('--watchAll') === -1) {
|
|
28
|
+
argv.push('--watchAll');
|
|
29
|
+
}
|
|
23
30
|
|
|
24
|
-
const jestConfig = createJestConfig(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
31
|
+
const jestConfig = createJestConfig(
|
|
32
|
+
relativePath => path.resolve(__dirname, '..', relativePath),
|
|
33
|
+
path.resolve(paths.appSrc, '..'),
|
|
34
|
+
paths.srcPaths,
|
|
35
|
+
config
|
|
36
|
+
);
|
|
29
37
|
|
|
30
|
-
argv.push(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
);
|
|
38
|
+
argv.push(
|
|
39
|
+
'--config',
|
|
40
|
+
JSON.stringify(
|
|
41
|
+
jestConfig
|
|
42
|
+
)
|
|
43
|
+
);
|
|
36
44
|
|
|
37
|
-
const testEnvironment = 'jsdom';
|
|
38
|
-
argv.push('--coverage', '--env', testEnvironment);
|
|
45
|
+
const testEnvironment = 'jsdom';
|
|
46
|
+
argv.push('--coverage', '--env', testEnvironment);
|
|
47
|
+
|
|
48
|
+
jest.run(argv);
|
|
49
|
+
}
|
|
39
50
|
|
|
40
|
-
|
|
51
|
+
start();
|
package/scripts/utils/clean.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
const paths = require('../../config/paths');
|
|
2
|
-
const config = require('config').util.loadFileConfigs(paths.appPath + '/config');
|
|
3
1
|
const { cleanDir } = require('../lib/fs');
|
|
4
2
|
|
|
5
3
|
/**
|
|
6
4
|
* Cleans up the output (build) directory.
|
|
7
5
|
*/
|
|
8
|
-
function clean() {
|
|
6
|
+
function clean(config) {
|
|
9
7
|
return Promise.all([
|
|
10
8
|
cleanDir('build/*', {
|
|
11
9
|
nosort: true,
|
|
@@ -17,11 +17,10 @@ const SimpleProgressWebpackPlugin = require('simple-progress-webpack-plugin');
|
|
|
17
17
|
const { SubresourceIntegrityPlugin } = require('webpack-subresource-integrity');
|
|
18
18
|
const crypto = require('crypto');
|
|
19
19
|
const SpeedMeasurePlugin = require('speed-measure-webpack-plugin');
|
|
20
|
+
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
|
|
20
21
|
|
|
21
22
|
const paths = require('../config/paths');
|
|
22
23
|
|
|
23
|
-
const config = require('config').util.loadFileConfigs(`${paths.appPath}/config`);
|
|
24
|
-
|
|
25
24
|
const pkg = require(`${paths.appPath}/package.json`);
|
|
26
25
|
const { name, version } = pkg;
|
|
27
26
|
const topLevelFrameworkPaths = [];
|
|
@@ -56,6 +55,8 @@ const mode = isDevEnv ? 'development' : 'production';
|
|
|
56
55
|
const isRuntimeDev = DEV_SERVER === 'true';
|
|
57
56
|
const smp = new SpeedMeasurePlugin({ disable: !MEASURE });
|
|
58
57
|
|
|
58
|
+
module.exports = async (config) => {
|
|
59
|
+
|
|
59
60
|
console.log(
|
|
60
61
|
`Building webpack project ${name}@${version}\n`,
|
|
61
62
|
Object.entries({
|
|
@@ -150,6 +151,9 @@ const isModuleCSS = module => (
|
|
|
150
151
|
// -----------------------------------------------------------------------------
|
|
151
152
|
const webpackConfig = ({ isClient }) => ({
|
|
152
153
|
mode,
|
|
154
|
+
experiments: {
|
|
155
|
+
topLevelAwait: true,
|
|
156
|
+
},
|
|
153
157
|
cache: { type: 'filesystem' },
|
|
154
158
|
|
|
155
159
|
output: {
|
|
@@ -167,9 +171,13 @@ const webpackConfig = ({ isClient }) => ({
|
|
|
167
171
|
'@hooks': path.resolve(paths.appSrc, 'hooks'),
|
|
168
172
|
'@components': path.resolve(paths.appSrc, 'components'),
|
|
169
173
|
'@baseComponents': path.resolve(paths.appSrc, 'base_components'),
|
|
170
|
-
'react/jsx-
|
|
171
|
-
'react/jsx-runtime': 'react/jsx-runtime
|
|
174
|
+
'react/jsx-runtime': require.resolve('react/jsx-runtime'),
|
|
175
|
+
'react/jsx-dev-runtime': require.resolve('react/jsx-dev-runtime'),
|
|
176
|
+
'react/jsx-runtime.js': require.resolve('react/jsx-runtime'),
|
|
177
|
+
'react/jsx-dev-runtime.js': require.resolve('react/jsx-dev-runtime'),
|
|
178
|
+
...(isClient ? { c12: false } : {}),
|
|
172
179
|
},
|
|
180
|
+
conditionNames: ['import', 'require', 'node', 'default'],
|
|
173
181
|
},
|
|
174
182
|
|
|
175
183
|
resolveLoader: {
|
|
@@ -194,6 +202,7 @@ const webpackConfig = ({ isClient }) => ({
|
|
|
194
202
|
babelrc: false,
|
|
195
203
|
configFile: false,
|
|
196
204
|
compact: isProdEnv,
|
|
205
|
+
isClient,
|
|
197
206
|
cacheDirectory: true,
|
|
198
207
|
cacheCompression: false,
|
|
199
208
|
customize: path.resolve(__dirname, '../config/babel/babel-custom-loader.js'),
|
|
@@ -207,6 +216,9 @@ const webpackConfig = ({ isClient }) => ({
|
|
|
207
216
|
test: /\.mjs$/,
|
|
208
217
|
include: /node_modules/,
|
|
209
218
|
type: 'javascript/auto',
|
|
219
|
+
resolve: {
|
|
220
|
+
fullySpecified: false,
|
|
221
|
+
}
|
|
210
222
|
},
|
|
211
223
|
{
|
|
212
224
|
test: /\.(woff|woff2|eot|ttf|otf)$/i,
|
|
@@ -273,65 +285,56 @@ const webpackConfig = ({ isClient }) => ({
|
|
|
273
285
|
stats: 'minimal'
|
|
274
286
|
});
|
|
275
287
|
|
|
276
|
-
const styleLoaders = ({ isClient }) => [
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
288
|
+
const styleLoaders = ({ isClient }) => [
|
|
289
|
+
{
|
|
290
|
+
loader: 'css-loader',
|
|
291
|
+
options: {
|
|
292
|
+
modules: {
|
|
293
|
+
exportOnlyLocals: !isClient,
|
|
294
|
+
localIdentName: '[local]',
|
|
295
|
+
},
|
|
296
|
+
importLoaders: 2,
|
|
283
297
|
},
|
|
284
|
-
importLoaders: 2,
|
|
285
298
|
},
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
299
|
+
{
|
|
300
|
+
loader: require.resolve('postcss-loader'),
|
|
301
|
+
options: {
|
|
302
|
+
postcssOptions: {
|
|
303
|
+
ident: 'postcss',
|
|
304
|
+
config: false,
|
|
305
|
+
plugins: [
|
|
306
|
+
[
|
|
307
|
+
'postcss-import',
|
|
308
|
+
{
|
|
309
|
+
addModulesDirectories: [
|
|
310
|
+
path.resolve(__dirname, '../node_modules'),
|
|
311
|
+
`${paths.appPath}/node_modules`
|
|
312
|
+
],
|
|
313
|
+
root: `${paths.appSrc}/styles/`
|
|
314
|
+
}
|
|
315
|
+
],
|
|
316
|
+
require('tailwindcss/nesting')(require('postcss-nested')),
|
|
317
|
+
'tailwindcss',
|
|
318
|
+
'postcss-flexbugs-fixes',
|
|
319
|
+
[
|
|
320
|
+
'postcss-preset-env',
|
|
321
|
+
{
|
|
322
|
+
autoprefixer: {
|
|
323
|
+
flexbox: 'no-2009',
|
|
324
|
+
},
|
|
325
|
+
stage: 3,
|
|
326
|
+
features: {
|
|
327
|
+
'nesting-rules': false,
|
|
328
|
+
},
|
|
329
|
+
browsers: pkg.browserslist
|
|
330
|
+
}
|
|
331
|
+
],
|
|
332
|
+
'postcss-modules-values',
|
|
315
333
|
],
|
|
316
|
-
|
|
317
|
-
'postcss-flexbugs-fixes'
|
|
318
|
-
],
|
|
334
|
+
},
|
|
319
335
|
},
|
|
320
336
|
},
|
|
321
|
-
|
|
322
|
-
{
|
|
323
|
-
loader: 'less-loader',
|
|
324
|
-
options: {
|
|
325
|
-
lessOptions: {
|
|
326
|
-
javascriptEnabled: true,
|
|
327
|
-
paths: [
|
|
328
|
-
`${paths.appSrc}/styles`,
|
|
329
|
-
`${paths.appPath}/node_modules/@machtwatch/react-ui`,
|
|
330
|
-
],
|
|
331
|
-
}
|
|
332
|
-
},
|
|
333
|
-
},
|
|
334
|
-
];
|
|
337
|
+
];
|
|
335
338
|
|
|
336
339
|
//
|
|
337
340
|
// Configuration for the client-side bundle (client.js)
|
|
@@ -472,6 +475,7 @@ const clientConfig = {
|
|
|
472
475
|
https: false,
|
|
473
476
|
util: false,
|
|
474
477
|
buffer: false,
|
|
478
|
+
assert: false,
|
|
475
479
|
}
|
|
476
480
|
},
|
|
477
481
|
module: {
|
|
@@ -508,68 +512,58 @@ const clientConfig = {
|
|
|
508
512
|
root: `${paths.appSrc}/styles/`
|
|
509
513
|
}
|
|
510
514
|
],
|
|
511
|
-
'tailwindcss/nesting',
|
|
515
|
+
require('tailwindcss/nesting')(require('postcss-nested')),
|
|
512
516
|
'tailwindcss',
|
|
517
|
+
'postcss-flexbugs-fixes',
|
|
513
518
|
[
|
|
514
519
|
'postcss-preset-env',
|
|
515
520
|
{
|
|
516
521
|
autoprefixer: { flexbox: 'no-2009' },
|
|
517
522
|
stage: 3,
|
|
523
|
+
features: {
|
|
524
|
+
'nesting-rules': false,
|
|
525
|
+
},
|
|
518
526
|
browsers: pkg.browserslist,
|
|
519
527
|
}
|
|
520
528
|
],
|
|
521
529
|
'postcss-modules-values',
|
|
522
|
-
'postcss-flexbugs-fixes',
|
|
523
530
|
],
|
|
524
531
|
},
|
|
525
532
|
},
|
|
526
533
|
},
|
|
527
534
|
],
|
|
528
535
|
},
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
filename: paths.appBuild
|
|
561
|
-
},
|
|
562
|
-
outputAsset: false
|
|
563
|
-
}),
|
|
564
|
-
// Define free variables
|
|
565
|
-
// https://webpack.github.io/docs/list-of-plugins.html#defineplugin
|
|
566
|
-
new webpack.DefinePlugin({
|
|
567
|
-
CONFIG: JSON.stringify(config.globals),
|
|
568
|
-
'process.env.DEV_SERVER': isRuntimeDev,
|
|
569
|
-
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
570
|
-
'process.env.BROWSER': true,
|
|
571
|
-
__DEVTOOLS__: isVerbose // <-------- DISABLE redux-devtools HERE
|
|
572
|
-
}),
|
|
536
|
+
]
|
|
537
|
+
},
|
|
538
|
+
plugins: [
|
|
539
|
+
...baseClientConfig.plugins,
|
|
540
|
+
new StyleLintPlugin({
|
|
541
|
+
configFile: `${paths.appPath}/.stylelintrc.json`,
|
|
542
|
+
extensions: ['css'],
|
|
543
|
+
exclude: ['node_modules', 'coverage'],
|
|
544
|
+
}),
|
|
545
|
+
isRuntimeDev && new ReactRefreshWebpackPlugin({
|
|
546
|
+
overlay: false,
|
|
547
|
+
}),
|
|
548
|
+
new webpack.HotModuleReplacementPlugin(),
|
|
549
|
+
new SubresourceIntegrityPlugin(),
|
|
550
|
+
new LoadablePlugin({
|
|
551
|
+
writeToDisk: {
|
|
552
|
+
filename: paths.appBuild
|
|
553
|
+
},
|
|
554
|
+
outputAsset: false
|
|
555
|
+
}),
|
|
556
|
+
// Define free variables
|
|
557
|
+
// https://webpack.github.io/docs/list-of-plugins.html#defineplugin
|
|
558
|
+
new webpack.DefinePlugin({
|
|
559
|
+
'process.env.DEV_SERVER': isRuntimeDev,
|
|
560
|
+
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
|
|
561
|
+
'process.env.BROWSER': true,
|
|
562
|
+
__DEVTOOLS__: isVerbose // <-------- DISABLE redux-devtools HERE
|
|
563
|
+
}),
|
|
564
|
+
new webpack.ProvidePlugin({
|
|
565
|
+
process: 'process/browser.js',
|
|
566
|
+
}),
|
|
573
567
|
|
|
574
568
|
new MiniCssExtractPlugin({
|
|
575
569
|
// Options similar to the same options in webpackOptions.output
|
|
@@ -676,83 +670,76 @@ const clientConfig = {
|
|
|
676
670
|
devtool: isDevEnv && useSourceMap ? 'eval' : false,
|
|
677
671
|
};
|
|
678
672
|
|
|
679
|
-
//
|
|
680
|
-
// Configuration for the server-side bundle (server.js)
|
|
681
|
-
// -----------------------------------------------------------------------------
|
|
682
|
-
const baseServerConfig = webpackConfig({ isClient: false });
|
|
683
|
-
const serverConfig = {
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
673
|
+
//
|
|
674
|
+
// Configuration for the server-side bundle (server.js)
|
|
675
|
+
// -----------------------------------------------------------------------------
|
|
676
|
+
const baseServerConfig = webpackConfig({ isClient: false });
|
|
677
|
+
const serverConfig = {
|
|
678
|
+
...baseServerConfig,
|
|
679
|
+
name: 'server',
|
|
680
|
+
target: 'node',
|
|
681
|
+
devtool: isDevEnv && useSourceMap ? 'eval' : false,
|
|
682
|
+
performance: false,
|
|
683
|
+
optimization: {
|
|
684
|
+
nodeEnv: false,
|
|
685
|
+
splitChunks: {
|
|
686
|
+
name: false,
|
|
687
|
+
cacheGroups: {
|
|
688
|
+
vendor: {
|
|
689
|
+
test: /[\\/]node_modules[\\/]/,
|
|
690
|
+
chunks: 'all',
|
|
691
|
+
enforce: true
|
|
692
|
+
}
|
|
698
693
|
}
|
|
699
|
-
}
|
|
700
|
-
},
|
|
701
|
-
minimize: isProdEnv,
|
|
702
|
-
minimizer: [
|
|
703
|
-
new TerserPlugin(),
|
|
704
|
-
new CssMinimizerPlugin()
|
|
705
|
-
]
|
|
706
|
-
},
|
|
707
|
-
entry: {
|
|
708
|
-
server: [
|
|
709
|
-
path.resolve(__dirname, './utils/polyfills.js'),
|
|
710
|
-
`${paths.appSrc}/server.js`
|
|
711
|
-
]
|
|
712
|
-
},
|
|
713
|
-
output: {
|
|
714
|
-
...baseServerConfig.output,
|
|
715
|
-
path: paths.appBuild,
|
|
716
|
-
filename: '[name].js',
|
|
717
|
-
libraryTarget: 'commonjs2',
|
|
718
|
-
},
|
|
719
|
-
module: {
|
|
720
|
-
...baseServerConfig.module,
|
|
721
|
-
rules: [
|
|
722
|
-
...baseServerConfig.module.rules,
|
|
723
|
-
{
|
|
724
|
-
test: /\.css$/,
|
|
725
|
-
use: styleLoaders({ isClient: false }).filter(
|
|
726
|
-
(loader) => loader.loader !== 'less-loader'
|
|
727
|
-
),
|
|
728
|
-
},
|
|
729
|
-
{
|
|
730
|
-
test: /\.less$/,
|
|
731
|
-
use: styleLoaders({ isClient: false }),
|
|
732
694
|
},
|
|
695
|
+
minimize: isProdEnv,
|
|
696
|
+
minimizer: [
|
|
697
|
+
new TerserPlugin(),
|
|
698
|
+
new CssMinimizerPlugin()
|
|
699
|
+
]
|
|
700
|
+
},
|
|
701
|
+
entry: {
|
|
702
|
+
server: [
|
|
703
|
+
path.resolve(__dirname, './utils/polyfills.js'),
|
|
704
|
+
`${paths.appSrc}/server.js`
|
|
705
|
+
]
|
|
706
|
+
},
|
|
707
|
+
output: {
|
|
708
|
+
...baseServerConfig.output,
|
|
709
|
+
path: paths.appBuild,
|
|
710
|
+
filename: '[name].js',
|
|
711
|
+
libraryTarget: 'commonjs2',
|
|
712
|
+
},
|
|
713
|
+
module: {
|
|
714
|
+
...baseServerConfig.module,
|
|
715
|
+
rules: [
|
|
716
|
+
...baseServerConfig.module.rules,
|
|
717
|
+
{
|
|
718
|
+
test: /\.css$/,
|
|
719
|
+
use: styleLoaders({ isClient: false }),
|
|
720
|
+
},
|
|
721
|
+
],
|
|
722
|
+
},
|
|
723
|
+
externalsPresets: { node: true },
|
|
724
|
+
externals: [
|
|
725
|
+
nodeExternals({
|
|
726
|
+
allowlist: [/^driver\.js/],
|
|
727
|
+
}),
|
|
728
|
+
/^\.\/assets\.json$/,
|
|
733
729
|
],
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
CONFIG: JSON.stringify(config.globals),
|
|
748
|
-
'process.env.DEV_SERVER': isRuntimeDev,
|
|
749
|
-
'process.env.BROWSER': false,
|
|
750
|
-
__DEVTOOLS__: false // <-------- DISABLE redux-devtools HERE
|
|
751
|
-
}),
|
|
752
|
-
// Do not create separate chunks of the server bundle
|
|
753
|
-
// https://webpack.github.io/docs/list-of-plugins.html#limitchunkcountplugin
|
|
754
|
-
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
|
|
755
|
-
].filter(Boolean),
|
|
730
|
+
plugins: [
|
|
731
|
+
...baseServerConfig.plugins,
|
|
732
|
+
// Define free variables
|
|
733
|
+
// https://webpack.github.io/docs/list-of-plugins.html#defineplugin
|
|
734
|
+
new webpack.DefinePlugin({
|
|
735
|
+
'process.env.DEV_SERVER': isRuntimeDev,
|
|
736
|
+
'process.env.BROWSER': false,
|
|
737
|
+
__DEVTOOLS__: false // <-------- DISABLE redux-devtools HERE
|
|
738
|
+
}),
|
|
739
|
+
// Do not create separate chunks of the server bundle
|
|
740
|
+
// https://webpack.github.io/docs/list-of-plugins.html#limitchunkcountplugin
|
|
741
|
+
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 })
|
|
742
|
+
].filter(Boolean),
|
|
756
743
|
|
|
757
744
|
node: {
|
|
758
745
|
global: false,
|
|
@@ -763,4 +750,5 @@ const serverConfig = {
|
|
|
763
750
|
|
|
764
751
|
let configs = smp.wrap([clientConfig, serverConfig]);
|
|
765
752
|
|
|
766
|
-
|
|
753
|
+
return configs;
|
|
754
|
+
};
|