@machtwatch/react-script 1.2.11-alpha.27 → 1.2.11-alpha.29

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.27",
3
+ "version": "1.2.11-alpha.29",
4
4
  "description": "Machtwatch React script",
5
5
  "author": "Danny Reza Miloen <danny@machtwatch.co.id>",
6
6
  "contributors": [],
@@ -65,7 +65,6 @@
65
65
  "browser-sync": "^2.26.7",
66
66
  "child_process": "^1.0.2",
67
67
  "compression-webpack-plugin": "^10.0.0",
68
- "config": "^3.3.9",
69
68
  "core-js": "^3.23.3",
70
69
  "css-loader": "^7.1.2",
71
70
  "css-minimizer-webpack-plugin": "^4.0.0",
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' })
package/scripts/start.js CHANGED
@@ -7,13 +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
-
16
- console.log('RUNNING LOCALL X')
15
+ const requireApp = createRequire(`${paths.appPath}/package.json`);
16
+ const { loadConfig } = requireApp('c12');
17
17
 
18
18
  const { format } = run;
19
19
 
@@ -71,12 +71,18 @@ async function start() {
71
71
  return server;
72
72
  }
73
73
 
74
+ const { config } = await loadConfig({
75
+ cwd: paths.appPath,
76
+ });
77
+
78
+ const webpackConfig = await require('./webpack.config')(config);
79
+
74
80
  server = express();
75
81
  server.use(errorOverlayMiddleware());
76
82
  server.use(express.static(paths.appPublic));
77
83
 
78
84
  // Configure client-side hot module replacement
79
- const clientConfig = webpackConfig.find(config => config.name === 'client');
85
+ const clientConfig = webpackConfig.find(c => c.name === 'client');
80
86
 
81
87
  clientConfig.entry.client = [path.resolve(`${__dirname}/lib/webpackHotDevClient`)]
82
88
  .concat(clientConfig.entry.client)
@@ -111,7 +117,7 @@ async function start() {
111
117
  );
112
118
 
113
119
  // Configure compilation
114
- await run(clean);
120
+ await run(clean, config);
115
121
 
116
122
  const clientCompiler = webpack(clientConfig);
117
123
  const serverCompiler = webpack(serverConfig);
@@ -189,12 +195,14 @@ async function start() {
189
195
  checkForUpdate(true);
190
196
  }
191
197
  })
192
- .catch(error => {
198
+ .catch(async error => {
193
199
  if (['abort', 'fail'].includes(app.hot.status())) {
194
200
  console.warn(`${hmrPrefix}Cannot apply update.`);
195
201
  delete require.cache[require.resolve(`${paths.appBuild}/server`)];
196
202
  // eslint-disable-next-line global-require, import/no-unresolved
197
- 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;
198
206
  console.warn(`${hmrPrefix}App has been reloaded.`);
199
207
  } else {
200
208
  console.warn(
@@ -225,7 +233,9 @@ async function start() {
225
233
 
226
234
  // Load compiled src/server.js as a middleware
227
235
  // eslint-disable-next-line global-require, import/no-unresolved
228
- 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;
229
239
  appPromiseIsResolved = true;
230
240
  appPromiseResolve();
231
241
 
@@ -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,
@@ -21,8 +21,6 @@ const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'
21
21
 
22
22
  const paths = require('../config/paths');
23
23
 
24
- const config = require('config').util.loadFileConfigs(`${paths.appPath}/config`);
25
-
26
24
  const pkg = require(`${paths.appPath}/package.json`);
27
25
  const { name, version } = pkg;
28
26
  const topLevelFrameworkPaths = [];
@@ -57,6 +55,8 @@ const mode = isDevEnv ? 'development' : 'production';
57
55
  const isRuntimeDev = DEV_SERVER === 'true';
58
56
  const smp = new SpeedMeasurePlugin({ disable: !MEASURE });
59
57
 
58
+ module.exports = async (config) => {
59
+
60
60
  console.log(
61
61
  `Building webpack project ${name}@${version}\n`,
62
62
  Object.entries({
@@ -151,6 +151,9 @@ const isModuleCSS = module => (
151
151
  // -----------------------------------------------------------------------------
152
152
  const webpackConfig = ({ isClient }) => ({
153
153
  mode,
154
+ experiments: {
155
+ topLevelAwait: true,
156
+ },
154
157
  cache: { type: 'filesystem' },
155
158
 
156
159
  output: {
@@ -172,6 +175,7 @@ const webpackConfig = ({ isClient }) => ({
172
175
  'react/jsx-dev-runtime': require.resolve('react/jsx-dev-runtime'),
173
176
  'react/jsx-runtime.js': require.resolve('react/jsx-runtime'),
174
177
  'react/jsx-dev-runtime.js': require.resolve('react/jsx-dev-runtime'),
178
+ ...(isClient ? { c12: false } : {}),
175
179
  },
176
180
  conditionNames: ['import', 'require', 'node', 'default'],
177
181
  },
@@ -479,6 +483,7 @@ const clientConfig = {
479
483
  https: false,
480
484
  util: false,
481
485
  buffer: false,
486
+ assert: false,
482
487
  }
483
488
  },
484
489
  module: {
@@ -573,7 +578,6 @@ const clientConfig = {
573
578
  // Define free variables
574
579
  // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
575
580
  new webpack.DefinePlugin({
576
- CONFIG: JSON.stringify(config.globals),
577
581
  'process.env.DEV_SERVER': isRuntimeDev,
578
582
  'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
579
583
  'process.env.BROWSER': true,
@@ -756,7 +760,6 @@ const serverConfig = {
756
760
  // Define free variables
757
761
  // https://webpack.github.io/docs/list-of-plugins.html#defineplugin
758
762
  new webpack.DefinePlugin({
759
- CONFIG: JSON.stringify(config.globals),
760
763
  'process.env.DEV_SERVER': isRuntimeDev,
761
764
  'process.env.BROWSER': false,
762
765
  __DEVTOOLS__: false // <-------- DISABLE redux-devtools HERE
@@ -775,4 +778,5 @@ const serverConfig = {
775
778
 
776
779
  let configs = smp.wrap([clientConfig, serverConfig]);
777
780
 
778
- module.exports = configs;
781
+ return configs;
782
+ };