@machtwatch/react-script 1.2.11-alpha.32 → 1.2.11-alpha.33

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@machtwatch/react-script",
3
- "version": "1.2.11-alpha.32",
3
+ "version": "1.2.11-alpha.33",
4
4
  "description": "Machtwatch React script",
5
5
  "author": "Danny Reza Miloen <danny@machtwatch.co.id>",
6
6
  "contributors": [],
@@ -15,7 +15,6 @@
15
15
  },
16
16
  "files": [
17
17
  "bin",
18
- "config",
19
18
  "scripts"
20
19
  ],
21
20
  "main": "./bin/react-script.js",
@@ -51,9 +50,10 @@
51
50
  "@babel/preset-react": "^7.17.12",
52
51
  "@loadable/babel-plugin": "^5.13.2",
53
52
  "@loadable/webpack-plugin": "^5.15.2",
53
+ "@pmmmwh/react-refresh-webpack-plugin": "0.6.2",
54
54
  "@svgr/webpack": "^6.2.1",
55
55
  "@testing-library/jest-dom": "^5.12.0",
56
- "@testing-library/react": "^11.2.7",
56
+ "@testing-library/react": "13.0.0",
57
57
  "assets-webpack-plugin": "7.1.1",
58
58
  "autoprefixer": "^10.4.20",
59
59
  "babel-jest": "^26.3.0",
@@ -64,7 +64,6 @@
64
64
  "browser-sync": "^2.26.7",
65
65
  "child_process": "^1.0.2",
66
66
  "compression-webpack-plugin": "^10.0.0",
67
- "config": "^3.3.9",
68
67
  "core-js": "^3.23.3",
69
68
  "css-loader": "^7.1.2",
70
69
  "css-minimizer-webpack-plugin": "^4.0.0",
@@ -80,8 +79,6 @@
80
79
  "imagemin-webp-webpack-plugin": "^3.3.6",
81
80
  "intersection-observer": "^0.5.1",
82
81
  "jest": "^26.4.2",
83
- "less": "^4.2.1",
84
- "less-loader": "^12.2.0",
85
82
  "mini-css-extract-plugin": "^2.6.1",
86
83
  "mkdirp": "^0.5.1",
87
84
  "null-loader": "^4.0.1",
@@ -90,11 +87,16 @@
90
87
  "postcss-flexbugs-fixes": "^5.0.2",
91
88
  "postcss-import": "^14.1.0",
92
89
  "postcss-loader": "^8.1.1",
90
+ "postcss-nested": "^6.0.1",
93
91
  "postcss-preset-env": "^7.7.1",
92
+ "process": "0.11.10",
94
93
  "promise": "^8.0.2",
95
94
  "purgecss-webpack-plugin": "^4.1.3",
95
+ "react": "18.3.1",
96
96
  "react-dev-utils": "^12.0.1",
97
- "react-error-overlay": "6.0.9",
97
+ "react-dom": "18.3.1",
98
+ "react-error-overlay": "6.0.11",
99
+ "react-refresh": "0.18.0",
98
100
  "recluster": "^0.4.5",
99
101
  "regenerator-runtime": "^0.13.3",
100
102
  "rimraf": "^2.6.3",
@@ -103,7 +105,7 @@
103
105
  "speed-measure-webpack-plugin": "^1.5.0",
104
106
  "style-loader": "^4.0.0",
105
107
  "stylelint": "^16.10.0",
106
- "stylelint-config-recommended-less": "^3.0.1",
108
+ "stylelint-config-recommended": "^14.0.1",
107
109
  "stylelint-webpack-plugin": "^5.0.1",
108
110
  "tailwindcss": "^3.4.17",
109
111
  "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 webpackConfig = require('./webpack.config');
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 run(clean);
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
- const fileName = encodeURIComponent(errorLocation.fileName);
15
- const lineNumber = encodeURIComponent(errorLocation.lineNumber || 1);
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
- fetch(
18
- // Keep in sync with react-dev-utils/errorOverlayMiddleware
19
- `${launchEditorEndpoint}?fileName=${fileName}&lineNumber=${lineNumber}`,
20
- );
21
- });
22
-
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
- });
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
- filename: '/assets/client.js',
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
- const webpackConfig = require('./webpack.config');
10
+
11
11
  const run = require('./utils/run');
12
12
  const clean = require('./utils/clean');
13
+ const { createRequire } = require('module');
13
14
 
14
- const config = require('config').util.loadFileConfigs(`${paths.appPath}/config`);
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(config => config.name === 'client');
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
- app = require(`${paths.appBuild}/server`).default;
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
- app = require(`${paths.appBuild}/server`).default;
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
- let argv = process.argv.slice(2);
22
+ async function start() {
23
+ const { config } = await loadConfig({ cwd: paths.appPath });
19
24
 
20
- if (argv.indexOf('--coverage') === -1 && argv.indexOf('--watchAll') === -1) {
21
- argv.push('--watchAll');
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
- relativePath => path.resolve(__dirname, '..', relativePath),
26
- path.resolve(paths.appSrc, '..'),
27
- paths.srcPaths
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
- '--config',
32
- JSON.stringify(
33
- jestConfig
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
- jest.run(argv);
51
+ start();
@@ -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-dev-runtime': 'react/jsx-dev-runtime.js',
171
- 'react/jsx-runtime': 'react/jsx-runtime.js'
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
- loader: 'css-loader',
279
- options: {
280
- modules: {
281
- exportOnlyLocals: !isClient,
282
- localIdentName: '[local]',
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
- loader: require.resolve('postcss-loader'),
289
- options: {
290
- postcssOptions: {
291
- ident: 'postcss',
292
- config: false,
293
- plugins: [
294
- [
295
- 'postcss-import',
296
- {
297
- addModulesDirectories: [
298
- path.resolve(__dirname, '../node_modules'),
299
- `${paths.appPath}/node_modules`
300
- ],
301
- root: `${paths.appSrc}/styles/`
302
- }
303
- ],
304
- 'tailwindcss/nesting',
305
- 'tailwindcss',
306
- [
307
- 'postcss-preset-env',
308
- {
309
- autoprefixer: {
310
- flexbox: 'no-2009',
311
- },
312
- stage: 3,
313
- browsers: pkg.browserslist
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
- 'postcss-modules-values',
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
- test: /\.less$/,
531
- use: [
532
- MiniCssExtractPlugin.loader,
533
- ...styleLoaders({ isClient: true }).filter(
534
- (loader) => loader.loader !== 'less-loader'
535
- ),
536
- {
537
- loader: 'less-loader',
538
- options: {
539
- lessOptions: {
540
- javascriptEnabled: true,
541
- paths: [`${paths.appSrc}/styles`],
542
- },
543
- },
544
- },
545
- ],
546
- }
547
- ]
548
- },
549
- plugins: [
550
- ...baseClientConfig.plugins,
551
- new StyleLintPlugin({
552
- configFile: `${paths.appPath}/.stylelintrc.json`,
553
- extensions: ['less'],
554
- exclude: ['node_modules', 'coverage'],
555
- }),
556
- new webpack.HotModuleReplacementPlugin(),
557
- new SubresourceIntegrityPlugin(),
558
- new LoadablePlugin({
559
- writeToDisk: {
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
- ...baseServerConfig,
685
- name: 'server',
686
- target: 'node',
687
- devtool: isDevEnv && useSourceMap ? 'eval' : false,
688
- performance: false,
689
- optimization: {
690
- nodeEnv: false,
691
- splitChunks: {
692
- name: false,
693
- cacheGroups: {
694
- vendor: {
695
- test: /[\\/]node_modules[\\/]/,
696
- chunks: 'all',
697
- enforce: true
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
- externalsPresets: { node: true },
736
- externals: [
737
- nodeExternals({
738
- allowlist: [/^driver\.js/],
739
- }),
740
- /^\.\/assets\.json$/,
741
- ],
742
- plugins: [
743
- ...baseServerConfig.plugins,
744
- // Define free variables
745
- // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
746
- new webpack.DefinePlugin({
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
- module.exports = configs;
753
+ return configs;
754
+ };
@@ -1,66 +0,0 @@
1
- module.exports = () => ({
2
- customOptions({ transform_runtime, ...loader }) {
3
- return {
4
- loader,
5
- custom: { ...transform_runtime }
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
- }
19
- ],
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.compact ? [
53
- require('@babel/plugin-transform-react-inline-elements'),
54
- require('@babel/plugin-transform-react-constant-elements')
55
- ] : []),
56
- ...(cfg.options.plugins || [])
57
- ],
58
- };
59
- },
60
- result(result) {
61
- return {
62
- ...result,
63
- code: `${result.code} \n// Generated by babel-custom-loader`
64
- };
65
- },
66
- });
package/config/env.js DELETED
@@ -1,67 +0,0 @@
1
- // @remove-on-eject-begin
2
- /**
3
- * Copyright (c) 2015-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove-on-eject-end
9
- 'use strict';
10
-
11
- const fs = require('fs');
12
- const path = require('path');
13
-
14
- const paths = require('./paths');
15
-
16
- // Make sure that including paths.js after env.js will read .env variables.
17
- delete require.cache[require.resolve('./paths')];
18
-
19
- // https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
20
- const dotenvFiles = [paths.dotenv].filter(Boolean);
21
- const appDirectory = fs.realpathSync(process.cwd());
22
-
23
- // Load environment variables from .env* files. Suppress warnings using silent
24
- // if this file is missing. dotenv will never modify any environment variables
25
- // that have already been set. Variable expansion is supported in .env files.
26
- // https://github.com/motdotla/dotenv
27
- // https://github.com/motdotla/dotenv-expand
28
- dotenvFiles.forEach(dotenvFile => {
29
- if (fs.existsSync(dotenvFile)) {
30
- require('dotenv-expand')(
31
- require('dotenv').config({ path: dotenvFile })
32
- );
33
- };
34
- });
35
-
36
- process.env.NODE_PATH = (process.env.NODE_PATH || '')
37
- .split(path.delimiter)
38
- .filter(folder => folder && !path.isAbsolute(folder))
39
- .map(folder => path.resolve(appDirectory, folder))
40
- .join(path.delimiter);
41
-
42
- function getClientEnvironment(publicUrl) {
43
- const raw = Object.keys(process.env)
44
- .reduce(
45
- (env, key) => {
46
- env[key] = process.env[key];
47
- return env;
48
- },
49
- {
50
- // Useful for determining whether we’re running in production mode.
51
- // Most importantly, it switches React into the correct mode.
52
- NODE_ENV: process.env.NODE_ENV || 'development',
53
- }
54
- );
55
-
56
- // Stringify all values so we can feed into Webpack DefinePlugin
57
- const stringified = {
58
- 'process.env': Object.keys(raw).reduce((env, key) => {
59
- env[key] = JSON.stringify(raw[key]);
60
- return env;
61
- }, {}),
62
- };
63
-
64
- return { raw, stringified };
65
- };
66
-
67
- module.exports = getClientEnvironment;
@@ -1,27 +0,0 @@
1
- 'use strict';
2
-
3
- const babelJest = require('babel-jest');
4
-
5
- module.exports = babelJest.createTransformer({
6
- babelrc: false,
7
- presets: [
8
- ['@babel/preset-react'],
9
- ['@babel/preset-env', {
10
- modules: 'auto',
11
- useBuiltIns: 'entry',
12
- corejs: 3,
13
- }]
14
- ],
15
- plugins: [
16
- require('@babel/plugin-transform-runtime'),
17
- require('@babel/plugin-syntax-dynamic-import'),
18
- require('@babel/plugin-proposal-export-default-from'),
19
- require('babel-plugin-dynamic-import-node'),
20
- [require('babel-plugin-transform-imports'), {
21
- '@machtwatch/react-ui': {
22
- transform: '@machtwatch/react-ui/lib/${member}',
23
- preventFullImport: true
24
- }
25
- }]
26
- ]
27
- });
@@ -1,88 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
- const fs = require('fs');
5
- const merge = require('deepmerge');
6
-
7
- module.exports = (resolve, rootDir, srcRoots) => {
8
- const toRelRootDir = f => '<rootDir>/' + path.relative(rootDir || '', f);
9
- const extendedPath = path.join(process.cwd(), 'extended-jest.config.js');
10
-
11
- let isExtendedConfigExisted = false;
12
- let extendedConfig = {};
13
-
14
- try {
15
- isExtendedConfigExisted = fs.existsSync(extendedPath);
16
- } catch (err) {
17
- console.error(err.message);
18
- }
19
-
20
- if (isExtendedConfigExisted) {
21
- try {
22
- extendedConfig = require(extendedPath);
23
- } catch (err) {
24
- console.error(err.message);
25
- }
26
- }
27
-
28
- const config = {
29
- setupFiles: [resolve('scripts/utils/polyfills.js')],
30
- testMatch: [
31
- "<rootDir>/src/shared/**/*.(spec|test).{js,jsx,mjs}"
32
- ],
33
- collectCoverageFrom: [
34
- "src/shared/**/*.{js,jsx,mjs}"
35
- ],
36
- coverageThreshold: {
37
- global: {
38
- branches: 80,
39
- functions: 80,
40
- lines: 80,
41
- statements: 80
42
- }
43
- },
44
- coverageReporters: [
45
- "lcov",
46
- "html"
47
- ],
48
- roots: srcRoots.map(toRelRootDir),
49
- testEnvironment: 'node',
50
- testEnvironmentOptions: {
51
- url: 'http://localhost'
52
- },
53
- transform: {
54
- '^.+\\.(js|jsx|mjs|cjs)$': resolve('config/jest/babelTransform.js'),
55
- '^.+\\.css$': resolve('config/jest/cssTransform.js'),
56
- '^.+\\.(graphql)$': resolve('config/jest/graphqlTransform.js'),
57
- '^(?!.*\\.(js|jsx|mjs|css|json|graphql)$)': resolve('config/jest/fileTransform.js'),
58
- },
59
- transformIgnorePatterns: [
60
- '^.+\\.module\\.css$',
61
- ],
62
- moduleFileExtensions: [
63
- 'web.js',
64
- 'mjs',
65
- 'js',
66
- 'json',
67
- 'web.jsx',
68
- 'jsx',
69
- 'node',
70
- ],
71
- testPathIgnorePatterns: [
72
- "/node_modules/",
73
- "<rootDir>/tests/",
74
- "<rootDir>/src/*.js",
75
- "<rootDir>/graphql/"
76
- ],
77
- setupFilesAfterEnv: [resolve('config/jest/jest-setup.js'), '<rootDir>/jest-setup.js'],
78
- verbose: true,
79
- };
80
-
81
- const combinedConfig = merge(config, extendedConfig);
82
-
83
- if (rootDir) {
84
- config.rootDir = rootDir;
85
- }
86
-
87
- return combinedConfig;
88
- };
@@ -1,13 +0,0 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- process() {
5
- return {
6
- code: 'module.exports = {};'
7
- };
8
- },
9
- getCacheKey() {
10
- // The output is always the same.
11
- return 'cssTransform';
12
- },
13
- };
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- const path = require('path');
4
-
5
- module.exports = {
6
- process(src, filename) {
7
- const assetFilename = JSON.stringify(path.basename(filename));
8
-
9
- if (filename.match(/\.svg$/)) {
10
- return {
11
- code: `module.exports = {
12
- __esModule: true,
13
- default: ${assetFilename},
14
- ReactComponent: () => ${assetFilename},
15
- };`
16
- };
17
- }
18
-
19
- return {
20
- code: `module.exports = ${assetFilename};`
21
- };
22
- },
23
- };
@@ -1,11 +0,0 @@
1
- 'use strict';
2
-
3
- const loader = require('graphql-tag/loader');
4
-
5
- module.exports = {
6
- process(src) {
7
- return {
8
- code: loader.call({ cacheable() {} }, src)
9
- };
10
- },
11
- };
@@ -1,4 +0,0 @@
1
- import "@testing-library/jest-dom";
2
- import config from 'config';
3
-
4
- global.CONFIG = config.globals;
package/config/paths.js DELETED
@@ -1,48 +0,0 @@
1
- // @remove-on-eject-begin
2
- /**
3
- * Copyright (c) 2015-present, Facebook, Inc.
4
- *
5
- * This source code is licensed under the MIT license found in the
6
- * LICENSE file in the root directory of this source tree.
7
- */
8
- // @remove-on-eject-end
9
- 'use strict';
10
-
11
- const path = require('path');
12
- const fs = require('fs');
13
-
14
- // Make sure any symlinks in the project folder are resolved:
15
- const appDirectory = fs.realpathSync(process.cwd());
16
-
17
- const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
18
- const resolveOwn = relativePath => path.resolve(__dirname, '..', relativePath);
19
-
20
- const useTemplate = appDirectory === fs.realpathSync(path.join(__dirname, '..'));
21
-
22
- if (useTemplate) {
23
- module.exports = {
24
- dotenv: resolveOwn('template/.env'),
25
- appPath: resolveOwn('template/'),
26
- appBuild: resolveOwn('template/build'),
27
- appPublic: resolveOwn('template/public'),
28
- appIndexJs: resolveOwn('template/src/index.js'),
29
- appPackageJson: resolveOwn('template/package.json'),
30
- appSrc: resolveOwn('template/src'),
31
- appConfig: resolveOwn('template/config/default'),
32
- appNodeModules: resolveOwn('template/node_modules'),
33
- };
34
- } else {
35
- module.exports = {
36
- dotenv: resolveApp('.env'),
37
- appPath: resolveApp('.'),
38
- appBuild: resolveApp('build'),
39
- appPublic: resolveApp('public'),
40
- appPackageJson: resolveApp('package.json'),
41
- appSrc: resolveApp('src'),
42
- appConfig: resolveApp('config/default'),
43
- appNodeModules: resolveApp('node_modules'),
44
- };
45
- }
46
-
47
- module.exports.srcPaths = [module.exports.appSrc];
48
- module.exports.useYarn = fs.existsSync(path.join(module.exports.appPath, 'yarn.lock'));