@modern-js/app-tools 2.53.0 → 2.53.1-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/dependencies/index.js +5 -13
- package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/esm/plugins/deploy/dependencies/index.js +20 -28
- package/dist/esm/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/esm/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +6 -14
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/js/modern/analyze/constants.js +15 -0
- package/dist/js/modern/analyze/generateCode.js +179 -0
- package/dist/js/modern/analyze/getBundleEntry.js +75 -0
- package/dist/js/modern/analyze/getClientRoutes.js +219 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +74 -0
- package/dist/js/modern/analyze/getHtmlTemplate.js +82 -0
- package/dist/js/modern/analyze/getServerRoutes.js +192 -0
- package/dist/js/modern/analyze/index.js +148 -0
- package/dist/js/modern/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/modern/analyze/makeLegalIdentifier.js +16 -0
- package/dist/js/modern/analyze/templates.js +88 -0
- package/dist/js/modern/analyze/utils.js +92 -0
- package/dist/js/modern/commands/build.js +154 -0
- package/dist/js/modern/commands/deploy.js +5 -0
- package/dist/js/modern/commands/dev.js +95 -0
- package/dist/js/modern/commands/index.js +3 -0
- package/dist/js/modern/commands/inspect.js +69 -0
- package/dist/js/modern/commands/start.js +31 -0
- package/dist/js/modern/exports/server.js +1 -0
- package/dist/js/modern/hooks.js +21 -0
- package/dist/js/modern/index.js +109 -0
- package/dist/js/modern/locale/en.js +35 -0
- package/dist/js/modern/locale/index.js +9 -0
- package/dist/js/modern/locale/zh.js +35 -0
- package/dist/js/modern/utils/config.js +78 -0
- package/dist/js/modern/utils/createCompiler.js +61 -0
- package/dist/js/modern/utils/createServer.js +18 -0
- package/dist/js/modern/utils/getSpecifiedEntries.js +36 -0
- package/dist/js/modern/utils/language.js +5 -0
- package/dist/js/modern/utils/printInstructions.js +11 -0
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +36 -0
- package/dist/js/node/analyze/generateCode.js +208 -0
- package/dist/js/node/analyze/getBundleEntry.js +89 -0
- package/dist/js/node/analyze/getClientRoutes.js +241 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +90 -0
- package/dist/js/node/analyze/getHtmlTemplate.js +106 -0
- package/dist/js/node/analyze/getServerRoutes.js +208 -0
- package/dist/js/node/analyze/index.js +178 -0
- package/dist/js/node/analyze/isDefaultExportFunction.js +50 -0
- package/dist/js/node/analyze/makeLegalIdentifier.js +24 -0
- package/dist/js/node/analyze/templates.js +106 -0
- package/dist/js/node/analyze/utils.js +113 -0
- package/dist/js/node/commands/build.js +174 -0
- package/dist/js/node/commands/deploy.js +14 -0
- package/dist/js/node/commands/dev.js +120 -0
- package/dist/js/node/commands/index.js +44 -0
- package/dist/js/node/commands/inspect.js +98 -0
- package/dist/js/node/commands/start.js +47 -0
- package/dist/js/node/exports/server.js +13 -0
- package/dist/js/node/hooks.js +39 -0
- package/dist/js/node/index.js +141 -0
- package/dist/js/node/locale/en.js +42 -0
- package/dist/js/node/locale/index.js +20 -0
- package/dist/js/node/locale/zh.js +42 -0
- package/dist/js/node/utils/config.js +103 -0
- package/dist/js/node/utils/createCompiler.js +81 -0
- package/dist/js/node/utils/createServer.js +35 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +46 -0
- package/dist/js/node/utils/language.js +13 -0
- package/dist/js/node/utils/printInstructions.js +22 -0
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +2 -1
- package/package.json +5 -5
@@ -0,0 +1,113 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.walkDirectory = exports.isRouteComponentFile = exports.getDefaultImports = void 0;
|
7
|
+
|
8
|
+
var _fs = _interopRequireDefault(require("fs"));
|
9
|
+
|
10
|
+
var _path = _interopRequireDefault(require("path"));
|
11
|
+
|
12
|
+
var _utils = require("@modern-js/utils");
|
13
|
+
|
14
|
+
var _constants = require("./constants");
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
const walkDirectory = dir => _fs.default.readdirSync(dir).reduce((previous, filename) => {
|
19
|
+
const filePath = _path.default.join(dir, filename);
|
20
|
+
|
21
|
+
if (_fs.default.statSync(filePath).isDirectory()) {
|
22
|
+
return [...previous, ...walkDirectory(filePath)];
|
23
|
+
} else {
|
24
|
+
return [...previous, filePath];
|
25
|
+
}
|
26
|
+
}, []);
|
27
|
+
|
28
|
+
exports.walkDirectory = walkDirectory;
|
29
|
+
|
30
|
+
const getDefaultImports = ({
|
31
|
+
entrypoint,
|
32
|
+
srcDirectory,
|
33
|
+
internalSrcAlias,
|
34
|
+
internalDirAlias,
|
35
|
+
internalDirectory
|
36
|
+
}) => {
|
37
|
+
const {
|
38
|
+
entryName,
|
39
|
+
fileSystemRoutes,
|
40
|
+
customBootstrap,
|
41
|
+
entry
|
42
|
+
} = entrypoint;
|
43
|
+
const imports = [{
|
44
|
+
specifiers: [{
|
45
|
+
local: 'React'
|
46
|
+
}],
|
47
|
+
value: 'react'
|
48
|
+
}, {
|
49
|
+
specifiers: [{
|
50
|
+
local: 'ReactDOM'
|
51
|
+
}],
|
52
|
+
value: (0, _utils.isReact18)(_path.default.join(internalDirectory, '../../')) ? 'react-dom/client' : 'react-dom'
|
53
|
+
}, {
|
54
|
+
specifiers: [{
|
55
|
+
imported: 'createApp'
|
56
|
+
}, {
|
57
|
+
imported: 'bootstrap'
|
58
|
+
}],
|
59
|
+
value: '@modern-js/runtime'
|
60
|
+
}, customBootstrap && {
|
61
|
+
specifiers: [{
|
62
|
+
local: 'customBootstrap'
|
63
|
+
}],
|
64
|
+
value: (0, _utils.normalizeToPosixPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
65
|
+
}].filter(Boolean);
|
66
|
+
|
67
|
+
if (fileSystemRoutes) {
|
68
|
+
const route = {
|
69
|
+
specifiers: [{
|
70
|
+
imported: 'routes'
|
71
|
+
}],
|
72
|
+
value: (0, _utils.normalizeToPosixPath)(`${internalDirAlias}/${entryName}/${_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`)
|
73
|
+
};
|
74
|
+
|
75
|
+
if (fileSystemRoutes.globalApp) {
|
76
|
+
imports.push({
|
77
|
+
specifiers: [{
|
78
|
+
local: 'App'
|
79
|
+
}],
|
80
|
+
value: (0, _utils.normalizeToPosixPath)(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
|
81
|
+
});
|
82
|
+
} else {
|
83
|
+
route.initialize = 'const App = false;';
|
84
|
+
}
|
85
|
+
|
86
|
+
imports.push(route);
|
87
|
+
} else {
|
88
|
+
imports.push({
|
89
|
+
specifiers: [{
|
90
|
+
local: 'App'
|
91
|
+
}],
|
92
|
+
value: (0, _utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
|
93
|
+
});
|
94
|
+
}
|
95
|
+
|
96
|
+
return imports;
|
97
|
+
};
|
98
|
+
|
99
|
+
exports.getDefaultImports = getDefaultImports;
|
100
|
+
|
101
|
+
const isRouteComponentFile = filePath => {
|
102
|
+
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
103
|
+
return false;
|
104
|
+
}
|
105
|
+
|
106
|
+
if (['.js', '.jsx', '.ts', '.tsx'].includes(_path.default.extname(filePath))) {
|
107
|
+
return true;
|
108
|
+
}
|
109
|
+
|
110
|
+
return false;
|
111
|
+
};
|
112
|
+
|
113
|
+
exports.isRouteComponentFile = isRouteComponentFile;
|
@@ -0,0 +1,174 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.build = void 0;
|
7
|
+
|
8
|
+
var _webpack = require("@modern-js/webpack");
|
9
|
+
|
10
|
+
var _core = require("@modern-js/core");
|
11
|
+
|
12
|
+
var _utils = require("@modern-js/utils");
|
13
|
+
|
14
|
+
var _routes = require("../utils/routes");
|
15
|
+
|
16
|
+
var _config = require("../utils/config");
|
17
|
+
|
18
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
19
|
+
|
20
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
21
|
+
|
22
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
23
|
+
|
24
|
+
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
25
|
+
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
26
|
+
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
27
|
+
|
28
|
+
const build = async (api, options) => {
|
29
|
+
let resolvedConfig = api.useResolvedConfigContext();
|
30
|
+
const appContext = api.useAppContext();
|
31
|
+
const hookRunners = api.useHookRunners();
|
32
|
+
const {
|
33
|
+
apiOnly
|
34
|
+
} = appContext;
|
35
|
+
|
36
|
+
if (apiOnly) {
|
37
|
+
const {
|
38
|
+
appDirectory,
|
39
|
+
distDirectory,
|
40
|
+
serverConfigFile
|
41
|
+
} = appContext;
|
42
|
+
await (0, _utils.emptyDir)(distDirectory);
|
43
|
+
await hookRunners.beforeBuild({
|
44
|
+
webpackConfigs: []
|
45
|
+
});
|
46
|
+
await (0, _config.buildServerConfig)({
|
47
|
+
appDirectory,
|
48
|
+
distDirectory,
|
49
|
+
configFile: serverConfigFile
|
50
|
+
});
|
51
|
+
await (0, _routes.generateRoutes)(appContext);
|
52
|
+
await hookRunners.afterBuild();
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
|
56
|
+
const webpackBuild = async (webpackConfig, type) => {
|
57
|
+
const compiler = (0, _webpack.webpack)(webpackConfig);
|
58
|
+
return new Promise((resolve, reject) => {
|
59
|
+
let label = process.env.NODE_ENV || '';
|
60
|
+
|
61
|
+
if (type && type !== 'legacy') {
|
62
|
+
label += ` ${type}`;
|
63
|
+
}
|
64
|
+
|
65
|
+
_utils.logger.info(`Creating a ${label} build...`);
|
66
|
+
|
67
|
+
compiler.run((err, stats) => {
|
68
|
+
let messages;
|
69
|
+
|
70
|
+
if (!err) {
|
71
|
+
messages = (0, _utils.formatWebpackMessages)(stats.toJson({
|
72
|
+
all: false,
|
73
|
+
warnings: true,
|
74
|
+
errors: true
|
75
|
+
}));
|
76
|
+
|
77
|
+
if (messages.errors.length === 0) {
|
78
|
+
_utils.logger.info(`File sizes after ${label} build:\n`);
|
79
|
+
|
80
|
+
(0, _utils.printFileSizesAfterBuild)(stats, previousFileSizes, distDirectory, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
|
81
|
+
|
82
|
+
_utils.logger.log();
|
83
|
+
}
|
84
|
+
} // When using run or watch, call close and wait for it to finish before calling run or watch again.
|
85
|
+
// Concurrent compilations will corrupt the output files.
|
86
|
+
|
87
|
+
|
88
|
+
compiler.close(closeErr => {
|
89
|
+
if (closeErr) {
|
90
|
+
_utils.logger.error(closeErr);
|
91
|
+
}
|
92
|
+
|
93
|
+
if (err) {
|
94
|
+
reject(err);
|
95
|
+
} else {
|
96
|
+
if (messages.errors.length) {
|
97
|
+
reject(new Error(messages.errors.join('\n\n')));
|
98
|
+
return;
|
99
|
+
}
|
100
|
+
|
101
|
+
resolve({
|
102
|
+
warnings: messages.warnings
|
103
|
+
});
|
104
|
+
}
|
105
|
+
});
|
106
|
+
});
|
107
|
+
});
|
108
|
+
};
|
109
|
+
|
110
|
+
resolvedConfig = _objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
111
|
+
cliOptions: options
|
112
|
+
});
|
113
|
+
|
114
|
+
_core.ResolvedConfigContext.set(resolvedConfig);
|
115
|
+
|
116
|
+
const {
|
117
|
+
distDirectory,
|
118
|
+
appDirectory,
|
119
|
+
serverConfigFile
|
120
|
+
} = appContext;
|
121
|
+
const previousFileSizes = await (0, _utils.measureFileSizesBeforeBuild)(distDirectory);
|
122
|
+
await (0, _utils.emptyDir)(distDirectory);
|
123
|
+
await (0, _config.buildServerConfig)({
|
124
|
+
appDirectory,
|
125
|
+
distDirectory,
|
126
|
+
configFile: serverConfigFile
|
127
|
+
});
|
128
|
+
const buildConfigs = [];
|
129
|
+
buildConfigs.push({
|
130
|
+
type: 'legacy',
|
131
|
+
config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT, appContext, resolvedConfig)
|
132
|
+
});
|
133
|
+
|
134
|
+
if (resolvedConfig.output.enableModernMode) {
|
135
|
+
buildConfigs.push({
|
136
|
+
type: 'modern',
|
137
|
+
config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.MODERN, appContext, resolvedConfig)
|
138
|
+
});
|
139
|
+
}
|
140
|
+
|
141
|
+
if ((0, _utils.isUseSSRBundle)(resolvedConfig)) {
|
142
|
+
buildConfigs.push({
|
143
|
+
type: 'ssr',
|
144
|
+
config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.NODE, appContext, resolvedConfig)
|
145
|
+
});
|
146
|
+
}
|
147
|
+
|
148
|
+
await hookRunners.beforeBuild({
|
149
|
+
webpackConfigs: buildConfigs.map(({
|
150
|
+
config
|
151
|
+
}) => config)
|
152
|
+
});
|
153
|
+
|
154
|
+
for (const buildConfig of buildConfigs) {
|
155
|
+
const {
|
156
|
+
type: buildType,
|
157
|
+
config
|
158
|
+
} = buildConfig;
|
159
|
+
|
160
|
+
try {
|
161
|
+
await webpackBuild(config, buildType);
|
162
|
+
} catch (error) {
|
163
|
+
(0, _utils.printBuildError)(error); // eslint-disable-next-line no-process-exit
|
164
|
+
|
165
|
+
process.exit(1);
|
166
|
+
}
|
167
|
+
}
|
168
|
+
|
169
|
+
await (0, _routes.generateRoutes)(appContext);
|
170
|
+
await hookRunners.afterBuild();
|
171
|
+
await (0, _config.emitResolvedConfig)(appDirectory, resolvedConfig);
|
172
|
+
};
|
173
|
+
|
174
|
+
exports.build = build;
|
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.deploy = void 0;
|
7
|
+
|
8
|
+
const deploy = async (api, options) => {
|
9
|
+
const hookRunners = api.useHookRunners();
|
10
|
+
await hookRunners.beforeDeploy(options);
|
11
|
+
await hookRunners.afterDeploy(options);
|
12
|
+
};
|
13
|
+
|
14
|
+
exports.deploy = deploy;
|
@@ -0,0 +1,120 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.dev = void 0;
|
7
|
+
|
8
|
+
var _utils = require("@modern-js/utils");
|
9
|
+
|
10
|
+
var _core = require("@modern-js/core");
|
11
|
+
|
12
|
+
var _createCompiler = require("../utils/createCompiler");
|
13
|
+
|
14
|
+
var _createServer = require("../utils/createServer");
|
15
|
+
|
16
|
+
var _routes = require("../utils/routes");
|
17
|
+
|
18
|
+
var _printInstructions = require("../utils/printInstructions");
|
19
|
+
|
20
|
+
var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
|
21
|
+
|
22
|
+
var _config = require("../utils/config");
|
23
|
+
|
24
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
25
|
+
|
26
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
27
|
+
|
28
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
29
|
+
|
30
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
31
|
+
|
32
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
33
|
+
|
34
|
+
const dev = async (api, options) => {
|
35
|
+
let userConfig = api.useResolvedConfigContext();
|
36
|
+
const appContext = api.useAppContext();
|
37
|
+
const hookRunners = api.useHookRunners();
|
38
|
+
userConfig = _objectSpread(_objectSpread({}, userConfig), {}, {
|
39
|
+
cliOptions: options
|
40
|
+
});
|
41
|
+
|
42
|
+
_core.ResolvedConfigContext.set(userConfig);
|
43
|
+
|
44
|
+
const {
|
45
|
+
appDirectory,
|
46
|
+
distDirectory,
|
47
|
+
port,
|
48
|
+
apiOnly,
|
49
|
+
entrypoints,
|
50
|
+
serverConfigFile
|
51
|
+
} = appContext;
|
52
|
+
const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
|
53
|
+
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
54
|
+
checkedEntries
|
55
|
+
}));
|
56
|
+
appContext.checkedEntries = checkedEntries;
|
57
|
+
|
58
|
+
_utils.fs.emptyDirSync(distDirectory);
|
59
|
+
|
60
|
+
await (0, _config.buildServerConfig)({
|
61
|
+
appDirectory,
|
62
|
+
distDirectory,
|
63
|
+
configFile: serverConfigFile,
|
64
|
+
options: {
|
65
|
+
esbuildOptions: {
|
66
|
+
watch: true
|
67
|
+
}
|
68
|
+
}
|
69
|
+
});
|
70
|
+
await hookRunners.beforeDev();
|
71
|
+
let compiler = null;
|
72
|
+
|
73
|
+
if (!apiOnly) {
|
74
|
+
const {
|
75
|
+
getWebpackConfig,
|
76
|
+
WebpackConfigTarget
|
77
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/webpack')));
|
78
|
+
const webpackConfigs = [(0, _utils.isSSR)(userConfig) && getWebpackConfig(WebpackConfigTarget.NODE, appContext, userConfig), getWebpackConfig(WebpackConfigTarget.CLIENT, appContext, userConfig)].filter(Boolean);
|
79
|
+
compiler = await (0, _createCompiler.createCompiler)({
|
80
|
+
api,
|
81
|
+
webpackConfigs,
|
82
|
+
userConfig,
|
83
|
+
appContext
|
84
|
+
});
|
85
|
+
}
|
86
|
+
|
87
|
+
await (0, _routes.generateRoutes)(appContext);
|
88
|
+
const app = await (0, _createServer.createServer)({
|
89
|
+
dev: _objectSpread(_objectSpread({}, {
|
90
|
+
client: {
|
91
|
+
port: port.toString()
|
92
|
+
},
|
93
|
+
devMiddleware: {
|
94
|
+
writeToDisk: file => !file.includes('.hot-update.')
|
95
|
+
},
|
96
|
+
hot: true,
|
97
|
+
liveReload: true,
|
98
|
+
port,
|
99
|
+
https: userConfig.dev.https
|
100
|
+
}), userConfig.tools.devServer),
|
101
|
+
compiler,
|
102
|
+
pwd: appDirectory,
|
103
|
+
config: userConfig,
|
104
|
+
serverConfigFile,
|
105
|
+
plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
|
106
|
+
});
|
107
|
+
app.listen(port, async err => {
|
108
|
+
if (err) {
|
109
|
+
throw err;
|
110
|
+
}
|
111
|
+
|
112
|
+
if (apiOnly) {
|
113
|
+
return (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
114
|
+
}
|
115
|
+
|
116
|
+
return _utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
|
117
|
+
});
|
118
|
+
};
|
119
|
+
|
120
|
+
exports.dev = dev;
|
@@ -0,0 +1,44 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
|
7
|
+
var _dev = require("./dev");
|
8
|
+
|
9
|
+
Object.keys(_dev).forEach(function (key) {
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
11
|
+
if (key in exports && exports[key] === _dev[key]) return;
|
12
|
+
Object.defineProperty(exports, key, {
|
13
|
+
enumerable: true,
|
14
|
+
get: function () {
|
15
|
+
return _dev[key];
|
16
|
+
}
|
17
|
+
});
|
18
|
+
});
|
19
|
+
|
20
|
+
var _build = require("./build");
|
21
|
+
|
22
|
+
Object.keys(_build).forEach(function (key) {
|
23
|
+
if (key === "default" || key === "__esModule") return;
|
24
|
+
if (key in exports && exports[key] === _build[key]) return;
|
25
|
+
Object.defineProperty(exports, key, {
|
26
|
+
enumerable: true,
|
27
|
+
get: function () {
|
28
|
+
return _build[key];
|
29
|
+
}
|
30
|
+
});
|
31
|
+
});
|
32
|
+
|
33
|
+
var _start = require("./start");
|
34
|
+
|
35
|
+
Object.keys(_start).forEach(function (key) {
|
36
|
+
if (key === "default" || key === "__esModule") return;
|
37
|
+
if (key in exports && exports[key] === _start[key]) return;
|
38
|
+
Object.defineProperty(exports, key, {
|
39
|
+
enumerable: true,
|
40
|
+
get: function () {
|
41
|
+
return _start[key];
|
42
|
+
}
|
43
|
+
});
|
44
|
+
});
|
@@ -0,0 +1,98 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.printInspectResult = exports.inspect = exports.getTagByWebpackTarget = exports.formatWebpackConfig = void 0;
|
7
|
+
|
8
|
+
var _path = _interopRequireDefault(require("path"));
|
9
|
+
|
10
|
+
var _webpack = require("@modern-js/webpack");
|
11
|
+
|
12
|
+
var _utils = require("@modern-js/utils");
|
13
|
+
|
14
|
+
var _webpackChain = _interopRequireDefault(require("@modern-js/utils/webpack-chain"));
|
15
|
+
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
17
|
+
|
18
|
+
const formatWebpackConfig = (config, verbose) => {
|
19
|
+
const stringify = _webpackChain.default.toString;
|
20
|
+
return `module.exports = ${stringify(config, {
|
21
|
+
verbose
|
22
|
+
})};`;
|
23
|
+
};
|
24
|
+
|
25
|
+
exports.formatWebpackConfig = formatWebpackConfig;
|
26
|
+
|
27
|
+
const inspect = (api, options) => {
|
28
|
+
process.env.NODE_ENV = options.env;
|
29
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
30
|
+
const appContext = api.useAppContext();
|
31
|
+
const outputFiles = [];
|
32
|
+
outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.CLIENT, appContext, resolvedConfig, options));
|
33
|
+
|
34
|
+
if (resolvedConfig.output.enableModernMode) {
|
35
|
+
outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.MODERN, appContext, resolvedConfig, options));
|
36
|
+
}
|
37
|
+
|
38
|
+
if ((0, _utils.isUseSSRBundle)(resolvedConfig)) {
|
39
|
+
outputFiles.push(printInspectResult(_webpack.WebpackConfigTarget.NODE, appContext, resolvedConfig, options));
|
40
|
+
}
|
41
|
+
|
42
|
+
_utils.logger.success('Inspect succeed, you can open following files to view the full webpack config: \n');
|
43
|
+
|
44
|
+
outputFiles.forEach(file => {
|
45
|
+
_utils.logger.log(` - ${_utils.chalk.yellow(_path.default.relative(appContext.appDirectory, file))}`);
|
46
|
+
});
|
47
|
+
|
48
|
+
_utils.logger.log();
|
49
|
+
};
|
50
|
+
|
51
|
+
exports.inspect = inspect;
|
52
|
+
|
53
|
+
const getTagByWebpackTarget = webpackTarget => {
|
54
|
+
switch (webpackTarget) {
|
55
|
+
case _webpack.WebpackConfigTarget.CLIENT:
|
56
|
+
return 'client';
|
57
|
+
|
58
|
+
case _webpack.WebpackConfigTarget.MODERN:
|
59
|
+
return 'modern';
|
60
|
+
|
61
|
+
case _webpack.WebpackConfigTarget.NODE:
|
62
|
+
return 'ssr';
|
63
|
+
|
64
|
+
default:
|
65
|
+
throw Error(`Unsupported webpack target: ${webpackTarget}`);
|
66
|
+
}
|
67
|
+
};
|
68
|
+
|
69
|
+
exports.getTagByWebpackTarget = getTagByWebpackTarget;
|
70
|
+
|
71
|
+
const printInspectResult = (webpackTarget, appContext, resolvedConfig, options) => {
|
72
|
+
const webpackConfig = (0, _webpack.getWebpackConfig)(webpackTarget, appContext, resolvedConfig);
|
73
|
+
const {
|
74
|
+
output,
|
75
|
+
verbose,
|
76
|
+
console = true
|
77
|
+
} = options;
|
78
|
+
const outputPath = output ? _path.default.posix.join(appContext.distDirectory, output) : appContext.distDirectory;
|
79
|
+
const tag = getTagByWebpackTarget(webpackTarget);
|
80
|
+
const outputFile = `webpack.${tag}.inspect.js`;
|
81
|
+
|
82
|
+
const outputFilePath = _path.default.posix.join(outputPath, outputFile);
|
83
|
+
|
84
|
+
const rawWebpackConfig = formatWebpackConfig(webpackConfig, verbose);
|
85
|
+
|
86
|
+
_utils.fs.outputFileSync(outputFilePath, rawWebpackConfig);
|
87
|
+
|
88
|
+
if (console) {
|
89
|
+
_utils.logger.log(`
|
90
|
+
webpack config for ${tag} build:
|
91
|
+
${rawWebpackConfig}
|
92
|
+
`);
|
93
|
+
}
|
94
|
+
|
95
|
+
return outputFilePath;
|
96
|
+
};
|
97
|
+
|
98
|
+
exports.printInspectResult = printInspectResult;
|
@@ -0,0 +1,47 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.start = void 0;
|
7
|
+
|
8
|
+
var _utils = require("@modern-js/utils");
|
9
|
+
|
10
|
+
var _prodServer = _interopRequireDefault(require("@modern-js/prod-server"));
|
11
|
+
|
12
|
+
var _printInstructions = require("../utils/printInstructions");
|
13
|
+
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
15
|
+
|
16
|
+
const start = async api => {
|
17
|
+
var _userConfig$source;
|
18
|
+
|
19
|
+
const appContext = api.useAppContext();
|
20
|
+
const userConfig = api.useResolvedConfigContext();
|
21
|
+
const hookRunners = api.useHookRunners();
|
22
|
+
const {
|
23
|
+
appDirectory,
|
24
|
+
port,
|
25
|
+
serverConfigFile
|
26
|
+
} = appContext;
|
27
|
+
|
28
|
+
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
29
|
+
|
30
|
+
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig$source = userConfig.source) === null || _userConfig$source === void 0 ? void 0 : _userConfig$source.entriesDir);
|
31
|
+
const app = await (0, _prodServer.default)({
|
32
|
+
pwd: appDirectory,
|
33
|
+
config: userConfig,
|
34
|
+
plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
|
35
|
+
serverConfigFile,
|
36
|
+
apiOnly
|
37
|
+
});
|
38
|
+
app.listen(port, async err => {
|
39
|
+
if (err) {
|
40
|
+
throw err;
|
41
|
+
}
|
42
|
+
|
43
|
+
await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
|
44
|
+
});
|
45
|
+
};
|
46
|
+
|
47
|
+
exports.start = start;
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
Object.defineProperty(exports, "defineConfig", {
|
7
|
+
enumerable: true,
|
8
|
+
get: function () {
|
9
|
+
return _config.defineServerConfig;
|
10
|
+
}
|
11
|
+
});
|
12
|
+
|
13
|
+
var _config = require("../utils/config");
|
@@ -0,0 +1,39 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.hooks = exports.beforePrintInstructions = exports.beforeDev = exports.beforeDeploy = exports.beforeCreateCompiler = exports.beforeBuild = exports.afterDev = exports.afterDeploy = exports.afterCreateCompiler = exports.afterBuild = void 0;
|
7
|
+
|
8
|
+
var _plugin = require("@modern-js/plugin");
|
9
|
+
|
10
|
+
const beforeDev = (0, _plugin.createAsyncWorkflow)();
|
11
|
+
exports.beforeDev = beforeDev;
|
12
|
+
const afterDev = (0, _plugin.createAsyncWorkflow)();
|
13
|
+
exports.afterDev = afterDev;
|
14
|
+
const beforeCreateCompiler = (0, _plugin.createAsyncWorkflow)();
|
15
|
+
exports.beforeCreateCompiler = beforeCreateCompiler;
|
16
|
+
const afterCreateCompiler = (0, _plugin.createAsyncWorkflow)();
|
17
|
+
exports.afterCreateCompiler = afterCreateCompiler;
|
18
|
+
const beforePrintInstructions = (0, _plugin.createAsyncWaterfall)();
|
19
|
+
exports.beforePrintInstructions = beforePrintInstructions;
|
20
|
+
const beforeBuild = (0, _plugin.createAsyncWorkflow)();
|
21
|
+
exports.beforeBuild = beforeBuild;
|
22
|
+
const afterBuild = (0, _plugin.createAsyncWorkflow)();
|
23
|
+
exports.afterBuild = afterBuild;
|
24
|
+
const beforeDeploy = (0, _plugin.createAsyncWorkflow)();
|
25
|
+
exports.beforeDeploy = beforeDeploy;
|
26
|
+
const afterDeploy = (0, _plugin.createAsyncWorkflow)();
|
27
|
+
exports.afterDeploy = afterDeploy;
|
28
|
+
const hooks = {
|
29
|
+
beforeDev,
|
30
|
+
afterDev,
|
31
|
+
beforeCreateCompiler,
|
32
|
+
afterCreateCompiler,
|
33
|
+
beforePrintInstructions,
|
34
|
+
beforeBuild,
|
35
|
+
afterBuild,
|
36
|
+
beforeDeploy,
|
37
|
+
afterDeploy
|
38
|
+
};
|
39
|
+
exports.hooks = hooks;
|