@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.1
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/CHANGELOG.md +181 -0
- package/dist/js/modern/analyze/generateCode.js +29 -37
- package/dist/js/modern/analyze/getBundleEntry.js +4 -12
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/modern/analyze/getFileSystemEntry.js +4 -17
- package/dist/js/modern/analyze/getHtmlTemplate.js +2 -9
- package/dist/js/modern/analyze/getServerRoutes.js +15 -32
- package/dist/js/modern/analyze/index.js +79 -22
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/modern/analyze/nestedRoutes.js +8 -33
- package/dist/js/modern/analyze/templates.js +22 -37
- package/dist/js/modern/analyze/utils.js +0 -7
- package/dist/js/modern/builder/builderPlugins/compatModern.js +30 -48
- package/dist/js/modern/builder/createHtmlConfig.js +2 -2
- package/dist/js/modern/builder/createOutputConfig.js +7 -4
- package/dist/js/modern/builder/createSourceConfig.js +0 -11
- package/dist/js/modern/builder/createToolsConfig.js +3 -10
- package/dist/js/modern/builder/index.js +24 -22
- package/dist/js/modern/builder/share.js +0 -4
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
- package/dist/js/modern/commands/build.js +6 -46
- package/dist/js/modern/commands/dev.js +4 -16
- package/dist/js/modern/commands/inspect.js +3 -20
- package/dist/js/modern/commands/start.js +0 -2
- package/dist/js/modern/index.js +6 -15
- package/dist/js/modern/utils/config.js +1 -12
- package/dist/js/modern/utils/createServer.js +0 -5
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
- package/dist/js/modern/utils/printInstructions.js +2 -1
- package/dist/js/modern/utils/routes.js +0 -2
- package/dist/js/node/analyze/generateCode.js +29 -60
- package/dist/js/node/analyze/getBundleEntry.js +4 -18
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
- package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
- package/dist/js/node/analyze/getFileSystemEntry.js +4 -25
- package/dist/js/node/analyze/getHtmlTemplate.js +2 -23
- package/dist/js/node/analyze/getServerRoutes.js +14 -40
- package/dist/js/node/analyze/index.js +79 -32
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
- package/dist/js/node/analyze/nestedRoutes.js +8 -41
- package/dist/js/node/analyze/templates.js +22 -47
- package/dist/js/node/analyze/utils.js +0 -20
- package/dist/js/node/builder/builderPlugins/compatModern.js +30 -59
- package/dist/js/node/builder/createHtmlConfig.js +2 -10
- package/dist/js/node/builder/createOutputConfig.js +7 -6
- package/dist/js/node/builder/createSourceConfig.js +0 -17
- package/dist/js/node/builder/createToolsConfig.js +3 -12
- package/dist/js/node/builder/index.js +24 -36
- package/dist/js/node/builder/share.js +0 -12
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
- package/dist/js/node/commands/build.js +4 -57
- package/dist/js/node/commands/deploy.js +0 -2
- package/dist/js/node/commands/dev.js +3 -27
- package/dist/js/node/commands/index.js +0 -6
- package/dist/js/node/commands/inspect.js +3 -27
- package/dist/js/node/commands/start.js +0 -11
- package/dist/js/node/exports/server.js +0 -1
- package/dist/js/node/hooks.js +0 -2
- package/dist/js/node/index.js +7 -34
- package/dist/js/node/locale/index.js +0 -4
- package/dist/js/node/utils/commands.js +0 -2
- package/dist/js/node/utils/config.js +1 -25
- package/dist/js/node/utils/createServer.js +0 -15
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
- package/dist/js/node/utils/language.js +0 -2
- package/dist/js/node/utils/printInstructions.js +2 -5
- package/dist/js/node/utils/routes.js +0 -5
- package/dist/js/treeshaking/analyze/generateCode.js +57 -100
- package/dist/js/treeshaking/analyze/getBundleEntry.js +11 -19
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +4 -17
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +2 -26
- package/dist/js/treeshaking/analyze/getServerRoutes.js +24 -37
- package/dist/js/treeshaking/analyze/index.js +185 -65
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
- package/dist/js/treeshaking/analyze/templates.js +31 -50
- package/dist/js/treeshaking/analyze/utils.js +7 -14
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +40 -59
- package/dist/js/treeshaking/builder/createHtmlConfig.js +15 -15
- package/dist/js/treeshaking/builder/createOutputConfig.js +26 -23
- package/dist/js/treeshaking/builder/createSourceConfig.js +7 -19
- package/dist/js/treeshaking/builder/createToolsConfig.js +16 -21
- package/dist/js/treeshaking/builder/index.js +38 -49
- package/dist/js/treeshaking/builder/share.js +0 -4
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
- package/dist/js/treeshaking/commands/build.js +26 -111
- package/dist/js/treeshaking/commands/deploy.js +0 -3
- package/dist/js/treeshaking/commands/dev.js +13 -35
- package/dist/js/treeshaking/commands/inspect.js +5 -28
- package/dist/js/treeshaking/commands/start.js +0 -9
- package/dist/js/treeshaking/index.js +2 -39
- package/dist/js/treeshaking/utils/config.js +1 -17
- package/dist/js/treeshaking/utils/createServer.js +0 -10
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
- package/dist/js/treeshaking/utils/printInstructions.js +0 -5
- package/dist/js/treeshaking/utils/routes.js +0 -4
- package/dist/types/analyze/index.d.ts +2 -3
- package/dist/types/analyze/nestedRoutes.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +0 -1
- package/dist/types/builder/index.d.ts +2 -6
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
- package/dist/types/commands/inspect.d.ts +1 -4
- package/dist/types/index.d.ts +0 -2
- package/dist/types/utils/config.d.ts +0 -1
- package/package.json +23 -22
- package/dist/js/modern/utils/createCompiler.js +0 -58
- package/dist/js/node/utils/createCompiler.js +0 -75
- package/dist/js/treeshaking/utils/createCompiler.js +0 -117
- package/dist/types/utils/createCompiler.d.ts +0 -12
|
@@ -6,11 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createBuilderInclude = createBuilderInclude;
|
|
7
7
|
exports.createBuilderModuleScope = createBuilderModuleScope;
|
|
8
8
|
exports.createSourceConfig = createSourceConfig;
|
|
9
|
-
|
|
10
9
|
var _path = require("path");
|
|
11
|
-
|
|
12
10
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
11
|
function createSourceConfig(normalizedConfig, appContext) {
|
|
15
12
|
const {
|
|
16
13
|
alias,
|
|
@@ -21,12 +18,10 @@ function createSourceConfig(normalizedConfig, appContext) {
|
|
|
21
18
|
preEntry
|
|
22
19
|
} = normalizedConfig.source;
|
|
23
20
|
const builderGlobalVars = globalVars || {};
|
|
24
|
-
|
|
25
21
|
for (const envVar of envVars || []) {
|
|
26
22
|
const envVarValue = process.env[envVar];
|
|
27
23
|
envVarValue && (builderGlobalVars[`process.env.${envVar}`] = envVarValue);
|
|
28
24
|
}
|
|
29
|
-
|
|
30
25
|
const builderModuleScope = createBuilderModuleScope(moduleScopes);
|
|
31
26
|
const builderInclude = createBuilderInclude(include, appContext);
|
|
32
27
|
return {
|
|
@@ -39,7 +34,6 @@ function createSourceConfig(normalizedConfig, appContext) {
|
|
|
39
34
|
resolveExtensionPrefix: '.web'
|
|
40
35
|
};
|
|
41
36
|
}
|
|
42
|
-
|
|
43
37
|
function createBuilderInclude(include, appContext) {
|
|
44
38
|
const defaultInclude = [appContext.internalDirectory];
|
|
45
39
|
const transformInclude = (include || []).map(include => {
|
|
@@ -47,37 +41,28 @@ function createBuilderInclude(include, appContext) {
|
|
|
47
41
|
if ((0, _path.isAbsolute)(include)) {
|
|
48
42
|
return include;
|
|
49
43
|
}
|
|
50
|
-
|
|
51
44
|
return new RegExp(include);
|
|
52
45
|
}
|
|
53
|
-
|
|
54
46
|
return include;
|
|
55
47
|
}).concat(defaultInclude); // concat default Include
|
|
56
48
|
|
|
57
49
|
const root = (0, _utils.findMonorepoRoot)(appContext.appDirectory);
|
|
58
|
-
|
|
59
50
|
if (!root) {
|
|
60
51
|
return transformInclude;
|
|
61
52
|
}
|
|
62
|
-
|
|
63
53
|
const modernjsMonorepo = (0, _utils.isModernjsMonorepo)(root);
|
|
64
|
-
|
|
65
54
|
if (modernjsMonorepo) {
|
|
66
55
|
const paths = _utils.globby.sync(_path.posix.join(root, 'features', '**', 'package.json'), {
|
|
67
56
|
ignore: ['**/node_modules/**/*']
|
|
68
57
|
}).map(pathname => (0, _path.dirname)(pathname) + _path.sep);
|
|
69
|
-
|
|
70
58
|
return [...paths, ...transformInclude];
|
|
71
59
|
}
|
|
72
|
-
|
|
73
60
|
return transformInclude;
|
|
74
61
|
}
|
|
75
|
-
|
|
76
62
|
function createBuilderModuleScope(moduleScopes) {
|
|
77
63
|
if (moduleScopes) {
|
|
78
64
|
let builderModuleScope = [];
|
|
79
65
|
const DEFAULT_SCOPES = ['./src', './shared', /node_modules/];
|
|
80
|
-
|
|
81
66
|
if (Array.isArray(moduleScopes)) {
|
|
82
67
|
if (isPrimitiveScope(moduleScopes)) {
|
|
83
68
|
builderModuleScope = DEFAULT_SCOPES.concat(moduleScopes);
|
|
@@ -87,12 +72,10 @@ function createBuilderModuleScope(moduleScopes) {
|
|
|
87
72
|
} else {
|
|
88
73
|
builderModuleScope = [DEFAULT_SCOPES, moduleScopes];
|
|
89
74
|
}
|
|
90
|
-
|
|
91
75
|
return builderModuleScope;
|
|
92
76
|
} else {
|
|
93
77
|
return undefined;
|
|
94
78
|
}
|
|
95
|
-
|
|
96
79
|
function isPrimitiveScope(items) {
|
|
97
80
|
return items.every(item => typeof item === 'string' || Object.prototype.toString.call(item) === '[object RegExp]');
|
|
98
81
|
}
|
|
@@ -5,15 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createBuilderTsChecker = createBuilderTsChecker;
|
|
7
7
|
exports.createToolsConfig = createToolsConfig;
|
|
8
|
-
|
|
9
8
|
var _utils = require("@modern-js/utils");
|
|
10
|
-
|
|
11
9
|
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; }
|
|
12
|
-
|
|
13
10
|
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; }
|
|
14
|
-
|
|
15
11
|
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; }
|
|
16
|
-
|
|
17
12
|
function createToolsConfig(normalizedConfig) {
|
|
18
13
|
const {
|
|
19
14
|
disableCssExtract,
|
|
@@ -59,18 +54,16 @@ function createToolsConfig(normalizedConfig) {
|
|
|
59
54
|
minify: typeof config.minify === 'object' ? _objectSpread(_objectSpread({}, config.minify), {}, {
|
|
60
55
|
removeComments: false
|
|
61
56
|
}) : config.minify
|
|
62
|
-
}),
|
|
57
|
+
}),
|
|
58
|
+
// eslint-disable-next-line no-nested-ternary
|
|
63
59
|
...(Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [htmlPlugin] : [])]
|
|
64
60
|
};
|
|
65
61
|
}
|
|
66
|
-
|
|
67
62
|
function createBuilderTsLoader(tsLoader, enableTsLoader) {
|
|
68
63
|
const useTsLoader = Boolean(enableTsLoader);
|
|
69
|
-
|
|
70
64
|
if (!useTsLoader) {
|
|
71
65
|
return undefined;
|
|
72
66
|
}
|
|
73
|
-
|
|
74
67
|
const defaultTsLoader = {
|
|
75
68
|
compilerOptions: {
|
|
76
69
|
target: 'es5',
|
|
@@ -81,12 +74,10 @@ function createBuilderTsLoader(tsLoader, enableTsLoader) {
|
|
|
81
74
|
};
|
|
82
75
|
return (_, utils) => (0, _utils.applyOptionsChain)(defaultTsLoader, tsLoader, utils);
|
|
83
76
|
}
|
|
84
|
-
|
|
85
77
|
function createBuilderTsChecker(output) {
|
|
86
|
-
if (output.enableTsLoader
|
|
78
|
+
if (output.enableTsLoader) {
|
|
87
79
|
return false;
|
|
88
80
|
}
|
|
89
|
-
|
|
90
81
|
const defaultTsChecker = {
|
|
91
82
|
issue: {
|
|
92
83
|
include: [{
|
|
@@ -3,54 +3,44 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.createBuilderForEdenX = createBuilderForEdenX;
|
|
6
7
|
exports.createBuilderOptions = createBuilderOptions;
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
|
|
9
8
|
var _builder = require("@modern-js/builder");
|
|
10
|
-
|
|
11
9
|
var _builderWebpackProvider = require("@modern-js/builder-webpack-provider");
|
|
12
|
-
|
|
13
10
|
var _utils = require("@modern-js/utils");
|
|
14
|
-
|
|
15
11
|
var _compatModern = require("./builderPlugins/compatModern");
|
|
16
|
-
|
|
17
12
|
var _createHtmlConfig = require("./createHtmlConfig");
|
|
18
|
-
|
|
19
13
|
var _createOutputConfig = require("./createOutputConfig");
|
|
20
|
-
|
|
21
14
|
var _createSourceConfig = require("./createSourceConfig");
|
|
22
|
-
|
|
23
15
|
var _createToolsConfig = require("./createToolsConfig");
|
|
24
|
-
|
|
25
16
|
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); }
|
|
26
|
-
|
|
27
17
|
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; }
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
target: _target = 'web',
|
|
31
|
-
normalizedConfig,
|
|
32
|
-
appContext,
|
|
33
|
-
compatPluginConfig
|
|
34
|
-
}) => {
|
|
35
|
-
const targets = Array.isArray(_target) ? _target : [_target];
|
|
36
|
-
|
|
18
|
+
function getBuilderTargets(normalizedConfig) {
|
|
19
|
+
const targets = ['web'];
|
|
37
20
|
if (normalizedConfig.output.enableModernMode && !targets.includes('modern-web')) {
|
|
38
21
|
targets.push('modern-web');
|
|
39
22
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
23
|
+
if ((0, _utils.isUseSSRBundle)(normalizedConfig)) {
|
|
24
|
+
targets.push('node');
|
|
25
|
+
}
|
|
26
|
+
return targets;
|
|
27
|
+
}
|
|
28
|
+
async function createBuilderForEdenX({
|
|
29
|
+
normalizedConfig,
|
|
30
|
+
appContext,
|
|
31
|
+
compatPluginConfig
|
|
32
|
+
}) {
|
|
33
|
+
const builderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
|
|
34
|
+
// create webpack provider
|
|
43
35
|
const webpackProvider = (0, _builderWebpackProvider.builderWebpackProvider)({
|
|
44
36
|
builderConfig
|
|
45
37
|
});
|
|
46
|
-
const
|
|
38
|
+
const target = getBuilderTargets(normalizedConfig);
|
|
39
|
+
const builderOptions = createBuilderOptions(target, appContext);
|
|
47
40
|
const builder = await (0, _builder.createBuilder)(webpackProvider, builderOptions);
|
|
48
41
|
await applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig);
|
|
49
42
|
return builder;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
exports.default = _default;
|
|
53
|
-
|
|
43
|
+
}
|
|
54
44
|
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
55
45
|
const source = (0, _createSourceConfig.createSourceConfig)(normalizedConfig, appContext);
|
|
56
46
|
const html = (0, _createHtmlConfig.createHtmlConfig)(normalizedConfig, appContext);
|
|
@@ -61,21 +51,24 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
61
51
|
html,
|
|
62
52
|
output,
|
|
63
53
|
tools,
|
|
54
|
+
dev: {
|
|
55
|
+
https: normalizedConfig.dev.https,
|
|
56
|
+
assetPrefix: normalizedConfig.dev.assetPrefix
|
|
57
|
+
},
|
|
64
58
|
performance: {
|
|
65
59
|
// `@modern-js/webpack` used to remove moment locale by default
|
|
66
60
|
removeMomentLocale: true
|
|
67
61
|
}
|
|
68
62
|
};
|
|
69
63
|
}
|
|
70
|
-
|
|
71
64
|
function createBuilderOptions(target, appContext) {
|
|
72
65
|
// create entries
|
|
66
|
+
|
|
73
67
|
const entries = {};
|
|
74
68
|
const {
|
|
75
69
|
entrypoints = [],
|
|
76
70
|
checkedEntries
|
|
77
71
|
} = appContext;
|
|
78
|
-
|
|
79
72
|
for (const {
|
|
80
73
|
entryName,
|
|
81
74
|
entry
|
|
@@ -83,14 +76,12 @@ function createBuilderOptions(target, appContext) {
|
|
|
83
76
|
if (checkedEntries && !checkedEntries.includes(entryName)) {
|
|
84
77
|
continue;
|
|
85
78
|
}
|
|
86
|
-
|
|
87
79
|
if (entryName in entries) {
|
|
88
80
|
entries[entryName].push(entry);
|
|
89
81
|
} else {
|
|
90
82
|
entries[entryName] = [entry];
|
|
91
83
|
}
|
|
92
84
|
}
|
|
93
|
-
|
|
94
85
|
return {
|
|
95
86
|
cwd: appContext.appDirectory,
|
|
96
87
|
target,
|
|
@@ -99,11 +90,10 @@ function createBuilderOptions(target, appContext) {
|
|
|
99
90
|
framework: appContext.metaName
|
|
100
91
|
};
|
|
101
92
|
}
|
|
93
|
+
|
|
102
94
|
/**
|
|
103
95
|
* register builder Plugin by condition
|
|
104
96
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
97
|
async function applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
108
98
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
|
109
99
|
const {
|
|
@@ -111,7 +101,6 @@ async function applyBuilderPlugins(builder, normalizedConfig, appContext, compat
|
|
|
111
101
|
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@modern-js/builder-plugin-node-polyfill')));
|
|
112
102
|
builder.addPlugins([PluginNodePolyfill()]);
|
|
113
103
|
}
|
|
114
|
-
|
|
115
104
|
if (normalizedConfig.tools.esbuild) {
|
|
116
105
|
const {
|
|
117
106
|
esbuild: esbuildOptions
|
|
@@ -124,6 +113,5 @@ async function applyBuilderPlugins(builder, normalizedConfig, appContext, compat
|
|
|
124
113
|
minimize: (0, _utils.applyOptionsChain)({}, esbuildOptions)
|
|
125
114
|
})]);
|
|
126
115
|
}
|
|
127
|
-
|
|
128
116
|
builder.addPlugins([(0, _compatModern.PluginCompatModern)(appContext, normalizedConfig, compatPluginConfig)]);
|
|
129
117
|
}
|
|
@@ -4,36 +4,25 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createCopyPattern = createCopyPattern;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _lodash = require("@modern-js/utils/lodash");
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
11
|
function createCopyPattern(appContext, config, patternsType, chain) {
|
|
17
12
|
const configDir = _path.default.resolve(appContext.appDirectory, config.source.configDir);
|
|
18
|
-
|
|
19
13
|
const uploadDir = _path.default.posix.join(configDir.replace(/\\/g, '/'), 'upload');
|
|
20
|
-
|
|
21
14
|
const publicDir = _path.default.posix.join(configDir.replace(/\\/g, '/'), 'public');
|
|
22
|
-
|
|
23
15
|
const minifiedJsRexExp = /\.min\.js/;
|
|
24
|
-
|
|
25
16
|
const info = file => ({
|
|
26
17
|
// If the file name ends with `.min.js`, we assume it's a compressed file.
|
|
27
18
|
// So we don't want copy-webpack-plugin to minify it.
|
|
28
19
|
// ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
|
|
29
20
|
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
30
21
|
});
|
|
31
|
-
|
|
32
22
|
if (patternsType === 'public') {
|
|
33
23
|
if (!chain) {
|
|
34
24
|
throw new Error("expect get a webpackChain, but receive 'undefined'");
|
|
35
25
|
}
|
|
36
|
-
|
|
37
26
|
return {
|
|
38
27
|
info,
|
|
39
28
|
from: '**/*',
|
|
@@ -45,7 +34,6 @@ function createCopyPattern(appContext, config, patternsType, chain) {
|
|
|
45
34
|
if (!/\.html?$/.test(absoluteFrom)) {
|
|
46
35
|
return content;
|
|
47
36
|
}
|
|
48
|
-
|
|
49
37
|
return (0, _lodash.template)(content.toString('utf8'))({
|
|
50
38
|
assetPrefix: (0, _utils.removeTailSlash)(chain.output.get('publicPath'))
|
|
51
39
|
});
|
|
@@ -4,43 +4,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.HtmlAsyncChunkPlugin = void 0;
|
|
7
|
-
|
|
8
7
|
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; }
|
|
9
|
-
|
|
10
8
|
class HtmlAsyncChunkPlugin {
|
|
11
9
|
constructor(htmlWebpackPlugin) {
|
|
12
10
|
_defineProperty(this, "name", void 0);
|
|
13
|
-
|
|
14
11
|
_defineProperty(this, "htmlWebpackPlugin", void 0);
|
|
15
|
-
|
|
16
12
|
this.name = 'HtmlAsyncChunkPlugin';
|
|
17
13
|
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
18
14
|
}
|
|
19
|
-
|
|
20
15
|
apply(compiler) {
|
|
21
16
|
compiler.hooks.compilation.tap(this.name, compilation => {
|
|
22
17
|
const hooks = this.htmlWebpackPlugin.getHooks(compilation);
|
|
23
18
|
hooks.alterAssetTagGroups.tap(this.name, assets => {
|
|
24
19
|
const tags = [...assets.headTags, ...assets.bodyTags];
|
|
25
|
-
|
|
26
20
|
for (const tag of tags) {
|
|
27
21
|
if (tag.tagName === 'script') {
|
|
28
22
|
const {
|
|
29
23
|
attributes
|
|
30
24
|
} = tag;
|
|
31
|
-
|
|
32
25
|
if (attributes && attributes.defer === true) {
|
|
33
26
|
attributes.async = true;
|
|
34
27
|
delete attributes.defer;
|
|
35
28
|
}
|
|
36
29
|
}
|
|
37
30
|
}
|
|
38
|
-
|
|
39
31
|
return assets;
|
|
40
32
|
});
|
|
41
33
|
});
|
|
42
34
|
}
|
|
43
|
-
|
|
44
35
|
}
|
|
45
|
-
|
|
46
36
|
exports.HtmlAsyncChunkPlugin = HtmlAsyncChunkPlugin;
|
|
@@ -4,50 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.BottomTemplatePlugin = void 0;
|
|
7
|
-
|
|
8
7
|
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; }
|
|
9
|
-
|
|
10
8
|
class BottomTemplatePlugin {
|
|
11
9
|
constructor(htmlWebpackPlugin) {
|
|
12
10
|
_defineProperty(this, "htmlWebpackPlugin", void 0);
|
|
13
|
-
|
|
14
11
|
_defineProperty(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
|
|
15
|
-
|
|
16
12
|
_defineProperty(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
|
|
17
|
-
|
|
18
13
|
_defineProperty(this, "name", void 0);
|
|
19
|
-
|
|
20
14
|
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
21
15
|
this.name = 'bottom-template';
|
|
22
16
|
}
|
|
23
|
-
|
|
24
17
|
apply(compiler) {
|
|
25
18
|
compiler.hooks.compilation.tap(this.name, compilation => {
|
|
26
19
|
this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(this.name, data => {
|
|
27
20
|
var _data$plugin$options;
|
|
28
|
-
|
|
29
21
|
if (!((_data$plugin$options = data.plugin.options) !== null && _data$plugin$options !== void 0 && _data$plugin$options.__internal__)) {
|
|
30
22
|
return data;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
23
|
+
}
|
|
24
|
+
// 含有 <!--<?- bottomTemplate ?>--> 占位符时才需要注入 bottom.html
|
|
34
25
|
if (this.bottomTemplateReg.test(data.html)) {
|
|
35
26
|
// 清空占位符
|
|
36
27
|
data.html = data.html.replace(this.bottomTemplateReg, '');
|
|
37
28
|
const {
|
|
38
29
|
bottomTemplate
|
|
39
30
|
} = data.plugin.options;
|
|
40
|
-
|
|
41
31
|
if (bottomTemplate) {
|
|
42
32
|
data.html = data.html.replace(this.bodyRegExp, match => `\n${bottomTemplate}\n${match}`);
|
|
43
33
|
}
|
|
44
34
|
}
|
|
45
|
-
|
|
46
35
|
return data;
|
|
47
36
|
});
|
|
48
37
|
});
|
|
49
38
|
}
|
|
50
|
-
|
|
51
39
|
}
|
|
52
|
-
|
|
53
40
|
exports.BottomTemplatePlugin = BottomTemplatePlugin;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _path = _interopRequireDefault(require("path"));
|
|
8
|
+
var _utils = require("@modern-js/utils");
|
|
9
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
+
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; }
|
|
11
|
+
const PLUGIN_NAME = 'ModernjsRoutePlugin';
|
|
12
|
+
class RouterPlugin {
|
|
13
|
+
constructor(options) {
|
|
14
|
+
_defineProperty(this, "existNestedRoutes", void 0);
|
|
15
|
+
this.existNestedRoutes = options.existNestedRoutes;
|
|
16
|
+
}
|
|
17
|
+
apply(compiler) {
|
|
18
|
+
const {
|
|
19
|
+
existNestedRoutes
|
|
20
|
+
} = this;
|
|
21
|
+
const {
|
|
22
|
+
target
|
|
23
|
+
} = compiler.options;
|
|
24
|
+
if (target === 'node' || Array.isArray(target) && target.includes('node')) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
if (!existNestedRoutes) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const {
|
|
31
|
+
webpack
|
|
32
|
+
} = compiler;
|
|
33
|
+
const {
|
|
34
|
+
Compilation,
|
|
35
|
+
sources
|
|
36
|
+
} = webpack;
|
|
37
|
+
const {
|
|
38
|
+
RawSource
|
|
39
|
+
} = sources;
|
|
40
|
+
const {
|
|
41
|
+
PROCESS_ASSETS_STAGE_REPORT
|
|
42
|
+
} = Compilation;
|
|
43
|
+
const outputPath = compiler.options.output.path;
|
|
44
|
+
const newAssetsMap = new Map();
|
|
45
|
+
const normalizePath = path => {
|
|
46
|
+
if (!path.endsWith('/')) {
|
|
47
|
+
return `${path}/`;
|
|
48
|
+
}
|
|
49
|
+
return path;
|
|
50
|
+
};
|
|
51
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, compilation => {
|
|
52
|
+
compilation.hooks.processAssets.tapPromise({
|
|
53
|
+
name: PLUGIN_NAME,
|
|
54
|
+
stage: PROCESS_ASSETS_STAGE_REPORT
|
|
55
|
+
}, async () => {
|
|
56
|
+
const stats = compilation.getStats().toJson({
|
|
57
|
+
chunkGroups: true,
|
|
58
|
+
chunks: true
|
|
59
|
+
});
|
|
60
|
+
const {
|
|
61
|
+
publicPath
|
|
62
|
+
} = stats;
|
|
63
|
+
const routeAssets = {};
|
|
64
|
+
const {
|
|
65
|
+
namedChunkGroups,
|
|
66
|
+
assetsByChunkName
|
|
67
|
+
} = stats;
|
|
68
|
+
if (!namedChunkGroups || !assetsByChunkName) {
|
|
69
|
+
_utils.logger.warn('Route manifest does not exist, performance will be affected');
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
for (const [name, chunkGroup] of Object.entries(namedChunkGroups)) {
|
|
73
|
+
routeAssets[name] = {
|
|
74
|
+
chunkIds: chunkGroup.chunks,
|
|
75
|
+
assets: assetsByChunkName[name].map(item => publicPath ? normalizePath(publicPath) + item : item)
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
const manifest = {
|
|
79
|
+
routeAssets
|
|
80
|
+
};
|
|
81
|
+
const injectedContent = `
|
|
82
|
+
;(function(){
|
|
83
|
+
window.${_utils.ROUTE_MANIFEST} = ${JSON.stringify(manifest)};
|
|
84
|
+
})();
|
|
85
|
+
`;
|
|
86
|
+
const entrypointsArray = Array.from(compilation.entrypoints.entries());
|
|
87
|
+
const entryChunkIds = entrypointsArray.map(entrypoint => entrypoint[0]);
|
|
88
|
+
const entryChunks = [...compilation.chunks].filter(chunk => {
|
|
89
|
+
return entryChunkIds.includes(chunk.name);
|
|
90
|
+
});
|
|
91
|
+
const entryChunkFiles = entryChunks.map(chunk => [...chunk.files][0]);
|
|
92
|
+
for (const file of entryChunkFiles) {
|
|
93
|
+
const asset = compilation.assets[file];
|
|
94
|
+
const newContent = `${injectedContent}${asset.source().toString()}`;
|
|
95
|
+
newAssetsMap.set(_path.default.join(outputPath, file), newContent);
|
|
96
|
+
compilation.updateAsset(file, new RawSource(newContent));
|
|
97
|
+
}
|
|
98
|
+
const filename = _path.default.join(outputPath, _utils.ROUTE_MINIFEST_FILE);
|
|
99
|
+
await _utils.fs.ensureFile(filename);
|
|
100
|
+
await _utils.fs.writeFile(filename, JSON.stringify(manifest, null, 2));
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
exports.default = RouterPlugin;
|
|
@@ -4,25 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.build = void 0;
|
|
7
|
-
|
|
8
7
|
var _core = require("@modern-js/core");
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _routes = require("../utils/routes");
|
|
13
|
-
|
|
14
10
|
var _config = require("../utils/config");
|
|
15
|
-
|
|
16
|
-
var _builder = _interopRequireDefault(require("../builder"));
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
11
|
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; }
|
|
21
|
-
|
|
22
12
|
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; }
|
|
23
|
-
|
|
24
13
|
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; }
|
|
25
|
-
|
|
26
14
|
const build = async (api, options) => {
|
|
27
15
|
let resolvedConfig = api.useResolvedConfigContext();
|
|
28
16
|
const appContext = api.useAppContext();
|
|
@@ -30,7 +18,6 @@ const build = async (api, options) => {
|
|
|
30
18
|
const {
|
|
31
19
|
apiOnly
|
|
32
20
|
} = appContext;
|
|
33
|
-
|
|
34
21
|
if (apiOnly) {
|
|
35
22
|
const {
|
|
36
23
|
appDirectory,
|
|
@@ -53,13 +40,10 @@ const build = async (api, options) => {
|
|
|
53
40
|
});
|
|
54
41
|
return;
|
|
55
42
|
}
|
|
56
|
-
|
|
57
43
|
resolvedConfig = _objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
|
58
44
|
cliOptions: options
|
|
59
45
|
});
|
|
60
|
-
|
|
61
46
|
_core.ResolvedConfigContext.set(resolvedConfig);
|
|
62
|
-
|
|
63
47
|
const {
|
|
64
48
|
distDirectory,
|
|
65
49
|
appDirectory,
|
|
@@ -70,51 +54,14 @@ const build = async (api, options) => {
|
|
|
70
54
|
distDirectory,
|
|
71
55
|
configFile: serverConfigFile
|
|
72
56
|
});
|
|
73
|
-
const targets = ['web'];
|
|
74
|
-
|
|
75
|
-
if (resolvedConfig.output.enableModernMode) {
|
|
76
|
-
targets.push('modern-web');
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if ((0, _utils.isUseSSRBundle)(resolvedConfig)) {
|
|
80
|
-
targets.push('node');
|
|
81
|
-
}
|
|
82
|
-
|
|
83
57
|
try {
|
|
84
|
-
|
|
85
|
-
target: targets,
|
|
86
|
-
appContext,
|
|
87
|
-
normalizedConfig: resolvedConfig,
|
|
88
|
-
compatPluginConfig: {
|
|
89
|
-
async onBeforeBuild({
|
|
90
|
-
bundlerConfigs
|
|
91
|
-
}) {
|
|
92
|
-
await (0, _routes.generateRoutes)(appContext);
|
|
93
|
-
await hookRunners.beforeBuild({
|
|
94
|
-
bundlerConfigs
|
|
95
|
-
});
|
|
96
|
-
},
|
|
97
|
-
|
|
98
|
-
async onAfterBuild({
|
|
99
|
-
stats
|
|
100
|
-
}) {
|
|
101
|
-
await hookRunners.afterBuild({
|
|
102
|
-
stats
|
|
103
|
-
});
|
|
104
|
-
await (0, _config.emitResolvedConfig)(appDirectory, resolvedConfig);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
|
|
58
|
+
var _appContext$builder;
|
|
110
59
|
_utils.logger.info('Create a production build...\n');
|
|
111
|
-
|
|
112
|
-
await builder.build();
|
|
60
|
+
await ((_appContext$builder = appContext.builder) === null || _appContext$builder === void 0 ? void 0 : _appContext$builder.build());
|
|
113
61
|
} catch (error) {
|
|
114
|
-
(0, _utils.printBuildError)(error);
|
|
115
|
-
|
|
62
|
+
(0, _utils.printBuildError)(error);
|
|
63
|
+
// eslint-disable-next-line no-process-exit
|
|
116
64
|
process.exit(1);
|
|
117
65
|
}
|
|
118
66
|
};
|
|
119
|
-
|
|
120
67
|
exports.build = build;
|
|
@@ -4,11 +4,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.deploy = void 0;
|
|
7
|
-
|
|
8
7
|
const deploy = async (api, options) => {
|
|
9
8
|
const hookRunners = api.useHookRunners();
|
|
10
9
|
await hookRunners.beforeDeploy(options);
|
|
11
10
|
await hookRunners.afterDeploy(options);
|
|
12
11
|
};
|
|
13
|
-
|
|
14
12
|
exports.deploy = deploy;
|