Skip to content

Commit 06e23ff

Browse files
authored
Remove babel transpilation step for server. (#210)
1 parent ce8a759 commit 06e23ff

File tree

13 files changed

+263
-253
lines changed

13 files changed

+263
-253
lines changed

.core/babel.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (semver.satisfies(semver.coerce(babelCoreVersion), '^7.4.0')) {
3232
}
3333
}
3434

35-
require('./reactium.log');
35+
require('./reactium.log.cjs');
3636

3737
global.ReactiumBabel = ReactiumBabel;
3838

.core/boot-hooks.js renamed to .core/boot-hooks.mjs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
1-
import path from 'path';
21
import _ from 'underscore';
3-
const globby = require('./globby-patch').sync;
2+
import path from 'node:path';
3+
import globbyPatched from './globby-patch.js'
4+
import { dirname } from '@atomic-reactor/dirname';
5+
6+
const __dirname = dirname(import.meta.url);
7+
const globby = globbyPatched.sync;
48

59
global.rootPath = path.resolve(__dirname, '..');
610

7-
module.exports = async () => {
11+
export default async () => {
812
// include boot DDD artifacts
913
if (!global.bootHooks) {
1014
global.bootHooks = globby([
1115
`${rootPath}/.core/**/reactium-boot.js`,
16+
`${rootPath}/.core/**/reactium-boot.mjs`,
17+
`${rootPath}/.core/**/reactium-boot.cjs`,
1218
`${rootPath}/src/**/reactium-boot.js`,
19+
`${rootPath}/src/**/reactium-boot.mjs`,
20+
`${rootPath}/src/**/reactium-boot.cjs`,
1321
`${rootPath}/reactium_modules/**/reactium-boot.js`,
22+
`${rootPath}/reactium_modules/**/reactium-boot.mjs`,
23+
`${rootPath}/reactium_modules/**/reactium-boot.cjs`,
1424
`${rootPath}/node_modules/**/reactium-plugin/**/reactium-boot.js`,
25+
`${rootPath}/node_modules/**/reactium-plugin/**/reactium-boot.mjs`,
26+
`${rootPath}/node_modules/**/reactium-plugin/**/reactium-boot.cjs`,
1527
]);
1628
}
1729

1830
if (!global.bootHookLoaded) {
1931
DEBUG('Loading boot hooks.');
2032
global.bootHookLoaded = [];
21-
global.bootHooks.map(item => {
33+
for (const item of global.bootHooks) {
2234
if (!bootHookLoaded.includes(item)) {
2335
const p = path.normalize(item);
24-
require(p);
36+
await import(p);
2537
bootHookLoaded.push(item);
2638
}
27-
});
28-
39+
}
40+
2941
ReactiumBoot.Hook.runSync('sdk-init', ReactiumBoot);
3042
await ReactiumBoot.Hook.run('sdk-init', ReactiumBoot);
3143
} else {

.core/gulp.bootup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const config = require('./gulp.config');
88
const webpackConfig = require('./webpack.config')(config);
99
const chalk = require('chalk');
1010

11-
require('./reactium.log');
11+
require('./reactium.log.cjs');
1212

1313
global.ReactiumGulp = ReactiumGulp;
1414

.core/gulp.tasks.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,7 @@ const reactium = (gulp, config, webpackConfig) => {
228228
crossEnvBin,
229229
'NODE_ENV=development',
230230
'nodemon',
231-
'./.core/index.js',
232-
'--exec',
233-
'babel-node',
231+
'./.core/index.mjs',
234232
],
235233
done,
236234
{ stdin: 'inherit' },

.core/index.js renamed to .core/index.mjs

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,19 @@ import bodyParser from 'body-parser';
88
import cookieParser from 'cookie-parser';
99
import cookieSession from 'cookie-session';
1010
import morgan from 'morgan';
11-
import path from 'path';
12-
import fs from 'fs';
1311
import op from 'object-path';
1412
import _ from 'underscore';
1513
import staticGzip from 'express-static-gzip';
1614
import chalk from 'chalk';
15+
import globals from './server-globals.mjs';
16+
import path from 'node:path';
17+
import fs from 'fs-extra';
18+
import globbyPatched from './globby-patch.js';
19+
import router from './server/router.mjs';
20+
import { dirname } from '@atomic-reactor/dirname';
1721

18-
const globby = require('./globby-patch').sync;
19-
20-
const globals = require('./server-globals');
22+
const __dirname = dirname(import.meta.url);
23+
const globby = globbyPatched.sync;
2124

2225
global.rootPath = path.resolve(__dirname, '..');
2326

@@ -101,7 +104,7 @@ const registeredMiddleware = async () => {
101104

102105
const reactiumModules = Object.keys(
103106
op.get(
104-
require(path.resolve(process.cwd(), 'package.json')),
107+
fs.readJsonSync(path.resolve(process.cwd(), 'package.json')),
105108
'reactiumDependencies',
106109
{},
107110
),
@@ -170,24 +173,29 @@ const registeredMiddleware = async () => {
170173
// default route handler
171174
ReactiumBoot.Server.Middleware.register('router', {
172175
name: 'router',
173-
use: require('./server/router').default,
176+
use: router,
174177
order: Enums.priority.neutral,
175178
});
176179
};
177180

178-
const registeredDevMiddleware = () => {
181+
const registeredDevMiddleware = async () => {
179182
const { Enums } = ReactiumBoot;
180183

181184
// set app variables
182185
app.set('x-powered-by', false);
183186

184187
// development mode
185188
if (process.env.NODE_ENV === 'development') {
186-
const webpack = require('webpack');
187-
const gulpConfig = require('./gulp.config');
188-
const webpackConfig = require('./webpack.config')(gulpConfig);
189-
const wpMiddlware = require('webpack-dev-middleware');
190-
const wpHotMiddlware = require('webpack-hot-middleware');
189+
const { default: webpack } = await import('webpack');
190+
const { default: gulpConfig } = await import('./gulp.config.js');
191+
const { default: webpackConfigFactory } = await import(
192+
'./webpack.config.js'
193+
);
194+
const webpackConfig = webpackConfigFactory(gulpConfig);
195+
const { default: wpMiddleware } = await import('webpack-dev-middleware');
196+
const { default: wpHotMiddleware } = await import(
197+
'webpack-hot-middleware'
198+
);
191199
const publicPath = `http://localhost:${PORT}/`;
192200

193201
// local development overrides for webpack config
@@ -202,7 +210,7 @@ const registeredDevMiddleware = () => {
202210

203211
ReactiumBoot.Server.Middleware.register('webpack', {
204212
name: 'webpack',
205-
use: wpMiddlware(compiler, {
213+
use: wpMiddleware(compiler, {
206214
serverSideRender: true,
207215
publicPath,
208216
}),
@@ -211,7 +219,7 @@ const registeredDevMiddleware = () => {
211219

212220
ReactiumBoot.Server.Middleware.register('hmr', {
213221
name: 'hmr',
214-
use: wpHotMiddlware(compiler, {
222+
use: wpHotMiddleware(compiler, {
215223
reload: true,
216224
}),
217225
order: Enums.priority.high,
@@ -317,7 +325,7 @@ const startServer = async () => {
317325
});
318326

319327
if (process.env.REACTIUM_TLS_MODE === 'on') {
320-
const spdy = require('spdy');
328+
const spdy = await import('spdy');
321329
const options = {
322330
key: fs.readFileSync(
323331
op.get(
File renamed without changes.

.core/sdk/reactium-boot.js

Lines changed: 0 additions & 22 deletions
This file was deleted.

.core/server-globals.js renamed to .core/server-globals.mjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1-
import path from 'path';
21
import op from 'object-path';
32
import _ from 'underscore';
4-
import reactiumBootHooks from './boot-hooks';
3+
import reactiumBootHooks from './boot-hooks.mjs';
4+
import path from 'node:path';
5+
import { dirname } from '@atomic-reactor/dirname';
6+
import ReactiumBoot from '@atomic-reactor/reactium-sdk-core';
7+
8+
global.ReactiumBoot = ReactiumBoot;
9+
10+
const __dirname = dirname(import.meta.url);
511

612
global.rootPath = path.resolve(__dirname, '..');
713

8-
module.exports = async () => {
9-
const ReactiumBoot = (await import('@atomic-reactor/reactium-sdk-core'))
10-
.default;
11-
global.ReactiumBoot = ReactiumBoot;
14+
export default async () => {
1215
global.defines = {};
1316

1417
const defaultPort = 3030;
@@ -35,7 +38,7 @@ module.exports = async () => {
3538

3639
global.TLS_PORT = op.get(process.env, 'TLS_PORT', 3443);
3740

38-
require('./reactium.log');
41+
await import('./reactium.log.cjs');
3942

4043
await reactiumBootHooks();
4144
};

0 commit comments

Comments
 (0)