@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
|
@@ -2,19 +2,19 @@ import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIt
|
|
|
2
2
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
3
|
export var index = function index(_ref) {
|
|
4
4
|
var mountId = _ref.mountId,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
imports = _ref.imports,
|
|
6
|
+
renderFunction = _ref.renderFunction,
|
|
7
|
+
exportStatement = _ref.exportStatement;
|
|
8
8
|
return "\nconst IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';\nconst IS_REACT18 = process.env.IS_REACT18 === 'true';\nconst MOUNT_ID = '".concat(mountId, "';\n\n").concat(imports, "\n\nlet AppWrapper = null;\n\nlet root = null;\n\nfunction render() {\n ").concat(renderFunction, "\n}\n\nAppWrapper = render();\n\n").concat(exportStatement, ";\n");
|
|
9
9
|
};
|
|
10
10
|
export var renderFunction = function renderFunction(_ref2) {
|
|
11
11
|
var plugins = _ref2.plugins,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
customBootstrap = _ref2.customBootstrap,
|
|
13
|
+
fileSystemRoutes = _ref2.fileSystemRoutes;
|
|
14
14
|
return "\n AppWrapper = createApp({\n plugins: [\n ".concat(plugins.map(function (_ref3) {
|
|
15
15
|
var name = _ref3.name,
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
options = _ref3.options,
|
|
17
|
+
args = _ref3.args;
|
|
18
18
|
return "".concat(name, "({...").concat(options, ", ...App?.config?.").concat(args || name, "}),");
|
|
19
19
|
}).join('\n'), "\n ]\n })(").concat(fileSystemRoutes ? '' : "App", ")\n\n if (IS_BROWSER) {\n ").concat(customBootstrap ? "customBootstrap(AppWrapper);" : "bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);", "\n }\n\n return AppWrapper\n");
|
|
20
20
|
};
|
|
@@ -23,46 +23,35 @@ export var html = function html(partials) {
|
|
|
23
23
|
};
|
|
24
24
|
export var routesForServer = function routesForServer(_ref4) {
|
|
25
25
|
var routes = _ref4.routes,
|
|
26
|
-
|
|
26
|
+
alias = _ref4.alias;
|
|
27
27
|
var name = alias.name,
|
|
28
|
-
|
|
28
|
+
basename = alias.basename;
|
|
29
29
|
var loaders = [];
|
|
30
|
-
|
|
31
30
|
var traverseRouteTree = function traverseRouteTree(route) {
|
|
32
31
|
var children;
|
|
33
|
-
|
|
34
32
|
if ('children' in route && route.children) {
|
|
35
33
|
var _route$children;
|
|
36
|
-
|
|
37
34
|
children = route === null || route === void 0 ? void 0 : (_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.map(traverseRouteTree);
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
var loader;
|
|
41
|
-
|
|
42
37
|
if (route.type === 'nested') {
|
|
43
38
|
if (route.loader) {
|
|
44
39
|
loaders.push(route.loader);
|
|
45
40
|
loader = "loader_".concat(loaders.length - 1);
|
|
46
41
|
}
|
|
47
42
|
}
|
|
48
|
-
|
|
49
43
|
var finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
50
44
|
loader: loader,
|
|
51
45
|
children: children
|
|
52
46
|
});
|
|
53
|
-
|
|
54
47
|
return finalRoute;
|
|
55
48
|
};
|
|
56
|
-
|
|
57
49
|
var routesCode = "\n export const routes = [\n ";
|
|
58
|
-
|
|
59
50
|
var _iterator = _createForOfIteratorHelper(routes),
|
|
60
|
-
|
|
61
|
-
|
|
51
|
+
_step;
|
|
62
52
|
try {
|
|
63
53
|
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
64
54
|
var route = _step.value;
|
|
65
|
-
|
|
66
55
|
if ('type' in route) {
|
|
67
56
|
var newRoute = traverseRouteTree(route);
|
|
68
57
|
routesCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loader_[^"])"/g, '$1'), ",");
|
|
@@ -75,7 +64,6 @@ export var routesForServer = function routesForServer(_ref4) {
|
|
|
75
64
|
} finally {
|
|
76
65
|
_iterator.f();
|
|
77
66
|
}
|
|
78
|
-
|
|
79
67
|
routesCode += "\n];";
|
|
80
68
|
var importLoadersCode = loaders.map(function (loader, index) {
|
|
81
69
|
var realLoaderPath = loader.replace(name, basename);
|
|
@@ -85,87 +73,81 @@ export var routesForServer = function routesForServer(_ref4) {
|
|
|
85
73
|
};
|
|
86
74
|
export var fileSystemRoutes = function fileSystemRoutes(_ref5) {
|
|
87
75
|
var routes = _ref5.routes,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
76
|
+
ssrMode = _ref5.ssrMode,
|
|
77
|
+
nestedRoutesEntry = _ref5.nestedRoutesEntry,
|
|
78
|
+
entryName = _ref5.entryName;
|
|
79
|
+
// The legacy mode and pages dir routes should use loadable
|
|
80
|
+
// nested routes + renderTostring should use loadable.lazy
|
|
81
|
+
// nested routes + renderToStream should use react.lazy
|
|
82
|
+
var importLazyCode = "\n import { lazy } from \"react\";\n import loadable, { lazy as loadableLazy } from \"@modern-js/runtime/loadable\"\n ";
|
|
91
83
|
var dataLoaderPath = '';
|
|
92
|
-
|
|
93
84
|
if (ssrMode) {
|
|
94
85
|
dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
95
|
-
|
|
96
86
|
if (nestedRoutesEntry) {
|
|
97
|
-
dataLoaderPath = "".concat(dataLoaderPath, "?routesDir=").concat(nestedRoutesEntry, "!");
|
|
87
|
+
dataLoaderPath = "".concat(dataLoaderPath, "?routesDir=").concat(nestedRoutesEntry, "&entryName=").concat(entryName, "!");
|
|
98
88
|
}
|
|
99
89
|
}
|
|
100
|
-
|
|
101
90
|
var loadings = [];
|
|
102
91
|
var errors = [];
|
|
103
92
|
var loaders = [];
|
|
104
|
-
|
|
105
93
|
var traverseRouteTree = function traverseRouteTree(route) {
|
|
106
94
|
var children;
|
|
107
|
-
|
|
108
95
|
if ('children' in route && route.children) {
|
|
109
96
|
var _route$children2;
|
|
110
|
-
|
|
111
97
|
children = route === null || route === void 0 ? void 0 : (_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.map(traverseRouteTree);
|
|
112
98
|
}
|
|
113
|
-
|
|
114
99
|
var loading;
|
|
115
100
|
var error;
|
|
116
101
|
var loader;
|
|
117
|
-
|
|
102
|
+
var component = '';
|
|
118
103
|
if (route.type === 'nested') {
|
|
119
104
|
if (route.loading) {
|
|
120
105
|
loadings.push(route.loading);
|
|
121
106
|
loading = "loading_".concat(loadings.length - 1);
|
|
122
107
|
}
|
|
123
|
-
|
|
124
108
|
if (route.error) {
|
|
125
109
|
errors.push(route.error);
|
|
126
110
|
error = "error_".concat(errors.length - 1);
|
|
127
111
|
}
|
|
128
|
-
|
|
129
112
|
if (route.loader) {
|
|
130
113
|
loaders.push(route.loader);
|
|
131
114
|
loader = "loader_".concat(loaders.length - 1);
|
|
132
115
|
}
|
|
116
|
+
if (route._component) {
|
|
117
|
+
if (ssrMode === 'stream') {
|
|
118
|
+
component = "lazy(() => import(/* webpackChunkName: \"".concat(route.id, "\" */ /* webpackMode: \"lazy-once\" */ '").concat(route._component, "'))");
|
|
119
|
+
} else {
|
|
120
|
+
component = "loadable(() => import(/* webpackChunkName: \"".concat(route.id, "\" */ /* webpackMode: \"lazy-once\" */ '").concat(route._component, "'))");
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} else if (route._component) {
|
|
124
|
+
component = "loadable(() => import('".concat(route._component, "'))");
|
|
133
125
|
}
|
|
134
|
-
|
|
135
126
|
var finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
136
127
|
loading: loading,
|
|
137
128
|
loader: loader,
|
|
138
129
|
error: error,
|
|
139
130
|
children: children
|
|
140
131
|
});
|
|
141
|
-
|
|
142
132
|
if (route._component) {
|
|
143
|
-
var component = ssrMode === 'stream' ? "lazy(() => import('".concat(route._component, "'))") : "loadable(() => import('".concat(route._component, "'))");
|
|
144
133
|
finalRoute.component = component;
|
|
145
134
|
}
|
|
146
|
-
|
|
147
135
|
return finalRoute;
|
|
148
136
|
};
|
|
149
|
-
|
|
150
137
|
var routeComponentsCode = "\n export const routes = [\n ";
|
|
151
|
-
|
|
152
138
|
var _iterator2 = _createForOfIteratorHelper(routes),
|
|
153
|
-
|
|
154
|
-
|
|
139
|
+
_step2;
|
|
155
140
|
try {
|
|
156
141
|
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
157
142
|
var route = _step2.value;
|
|
158
|
-
|
|
159
143
|
if ('type' in route) {
|
|
160
144
|
var newRoute = traverseRouteTree(route);
|
|
161
|
-
routeComponentsCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loadable
|
|
145
|
+
routeComponentsCode += "".concat(JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, '$1').replace(/"(loadableLazy.*\))"/g, '$1').replace(/"(lazy.*\))"/g, '$1').replace(/"(loading_[^"])"/g, '$1').replace(/"(loader_[^"])"/g, '$1').replace(/"(error_[^"])"/g, '$1').replace(/\\"/g, '"'), ",");
|
|
162
146
|
} else {
|
|
163
|
-
var component =
|
|
164
|
-
|
|
147
|
+
var component = "loadable(() => import('".concat(route._component, "'))");
|
|
165
148
|
var finalRoute = _objectSpread(_objectSpread({}, route), {}, {
|
|
166
149
|
component: component
|
|
167
150
|
});
|
|
168
|
-
|
|
169
151
|
routeComponentsCode += "".concat(JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, '$1').replace(/"(lazy[^"]*)"/g, '$1'), ",");
|
|
170
152
|
}
|
|
171
153
|
}
|
|
@@ -174,7 +156,6 @@ export var fileSystemRoutes = function fileSystemRoutes(_ref5) {
|
|
|
174
156
|
} finally {
|
|
175
157
|
_iterator2.f();
|
|
176
158
|
}
|
|
177
|
-
|
|
178
159
|
routeComponentsCode += "\n];";
|
|
179
160
|
var importLoadingCode = loadings.map(function (loading, index) {
|
|
180
161
|
return "import loading_".concat(index, " from '").concat(loading, "';\n");
|
|
@@ -6,7 +6,6 @@ import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
|
|
|
6
6
|
export var walkDirectory = function walkDirectory(dir) {
|
|
7
7
|
return fs.readdirSync(dir).reduce(function (previous, filename) {
|
|
8
8
|
var filePath = path.join(dir, filename);
|
|
9
|
-
|
|
10
9
|
if (fs.statSync(filePath).isDirectory()) {
|
|
11
10
|
return [].concat(_toConsumableArray(previous), _toConsumableArray(walkDirectory(filePath)));
|
|
12
11
|
} else {
|
|
@@ -16,14 +15,14 @@ export var walkDirectory = function walkDirectory(dir) {
|
|
|
16
15
|
};
|
|
17
16
|
export var getDefaultImports = function getDefaultImports(_ref) {
|
|
18
17
|
var entrypoint = _ref.entrypoint,
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
srcDirectory = _ref.srcDirectory,
|
|
19
|
+
internalSrcAlias = _ref.internalSrcAlias,
|
|
20
|
+
internalDirAlias = _ref.internalDirAlias,
|
|
21
|
+
internalDirectory = _ref.internalDirectory;
|
|
23
22
|
var entryName = entrypoint.entryName,
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
fileSystemRoutes = entrypoint.fileSystemRoutes,
|
|
24
|
+
customBootstrap = entrypoint.customBootstrap,
|
|
25
|
+
entry = entrypoint.entry;
|
|
27
26
|
var imports = [{
|
|
28
27
|
specifiers: [{
|
|
29
28
|
local: 'React'
|
|
@@ -47,7 +46,6 @@ export var getDefaultImports = function getDefaultImports(_ref) {
|
|
|
47
46
|
}],
|
|
48
47
|
value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
|
49
48
|
}].filter(Boolean);
|
|
50
|
-
|
|
51
49
|
if (fileSystemRoutes) {
|
|
52
50
|
var route = {
|
|
53
51
|
specifiers: [{
|
|
@@ -55,7 +53,6 @@ export var getDefaultImports = function getDefaultImports(_ref) {
|
|
|
55
53
|
}],
|
|
56
54
|
value: normalizeToPosixPath("".concat(internalDirAlias, "/").concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME))
|
|
57
55
|
};
|
|
58
|
-
|
|
59
56
|
if (fileSystemRoutes.globalApp) {
|
|
60
57
|
imports.push({
|
|
61
58
|
specifiers: [{
|
|
@@ -66,7 +63,6 @@ export var getDefaultImports = function getDefaultImports(_ref) {
|
|
|
66
63
|
} else {
|
|
67
64
|
route.initialize = 'const App = false;';
|
|
68
65
|
}
|
|
69
|
-
|
|
70
66
|
imports.push(route);
|
|
71
67
|
} else {
|
|
72
68
|
imports.push({
|
|
@@ -76,18 +72,15 @@ export var getDefaultImports = function getDefaultImports(_ref) {
|
|
|
76
72
|
value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
|
|
77
73
|
});
|
|
78
74
|
}
|
|
79
|
-
|
|
80
75
|
return imports;
|
|
81
76
|
};
|
|
82
77
|
export var isRouteComponentFile = function isRouteComponentFile(filePath) {
|
|
83
78
|
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
84
79
|
return false;
|
|
85
80
|
}
|
|
86
|
-
|
|
87
81
|
if (['.js', '.jsx', '.ts', '.tsx'].includes(path.extname(filePath))) {
|
|
88
82
|
return true;
|
|
89
83
|
}
|
|
90
|
-
|
|
91
84
|
return false;
|
|
92
85
|
};
|
|
93
86
|
export var replaceWithAlias = function replaceWithAlias(base, filePath, alias) {
|
|
@@ -9,7 +9,7 @@ import { getEntryOptions } from '@modern-js/utils';
|
|
|
9
9
|
import { BottomTemplatePlugin } from "../webpackPlugins/htmlBottomTemplate";
|
|
10
10
|
import { HtmlAsyncChunkPlugin } from "../webpackPlugins/htmlAsyncChunkPlugin";
|
|
11
11
|
import { createCopyPattern } from "../share";
|
|
12
|
-
|
|
12
|
+
import RouterPlugin from "../webpackPlugins/routerPlugin";
|
|
13
13
|
/**
|
|
14
14
|
* Provides default configuration consistent with `@modern-js/webpack`
|
|
15
15
|
*/
|
|
@@ -25,15 +25,14 @@ export var PluginCompatModern = function PluginCompatModern(appContext, modernCo
|
|
|
25
25
|
}
|
|
26
26
|
});
|
|
27
27
|
}
|
|
28
|
-
|
|
29
28
|
return config;
|
|
30
29
|
});
|
|
31
30
|
api.modifyWebpackChain(function (chain, _ref) {
|
|
32
31
|
var target = _ref.target,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
var builderNormalizedConfig = api.getNormalizedConfig();
|
|
36
|
-
|
|
32
|
+
CHAIN_ID = _ref.CHAIN_ID,
|
|
33
|
+
isProd = _ref.isProd;
|
|
34
|
+
var builderNormalizedConfig = api.getNormalizedConfig();
|
|
35
|
+
// set webpack config name
|
|
37
36
|
if (target === 'node') {
|
|
38
37
|
chain.name('server');
|
|
39
38
|
} else if (target === 'modern-web') {
|
|
@@ -41,13 +40,12 @@ export var PluginCompatModern = function PluginCompatModern(appContext, modernCo
|
|
|
41
40
|
} else {
|
|
42
41
|
chain.name('client');
|
|
43
42
|
}
|
|
43
|
+
chain.resolve.modules.add('node_modules').add(join(api.context.rootPath, 'node_modules'));
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
// apply node compat
|
|
47
46
|
if (target === 'node') {
|
|
48
47
|
applyNodeCompat(chain, modernConfig, isProd);
|
|
49
48
|
}
|
|
50
|
-
|
|
51
49
|
if (isHtmlEnabled(builderNormalizedConfig, target)) {
|
|
52
50
|
applyBottomHtmlWebpackPlugin({
|
|
53
51
|
api: api,
|
|
@@ -61,36 +59,39 @@ export var PluginCompatModern = function PluginCompatModern(appContext, modernCo
|
|
|
61
59
|
CHAIN_ID: CHAIN_ID,
|
|
62
60
|
modernConfig: modernConfig
|
|
63
61
|
});
|
|
64
|
-
}
|
|
65
|
-
// const copyPatterns = createCopyPatterns(chain, appContext, modernConfig);
|
|
66
|
-
|
|
62
|
+
}
|
|
67
63
|
|
|
64
|
+
// apply copy plugin
|
|
65
|
+
// const copyPatterns = createCopyPatterns(chain, appContext, modernConfig);
|
|
68
66
|
var defaultCopyPattern = createCopyPattern(appContext, modernConfig, 'public', chain);
|
|
69
67
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(function (args) {
|
|
70
68
|
var _args$;
|
|
71
|
-
|
|
72
69
|
return [{
|
|
73
70
|
patterns: [].concat(_toConsumableArray(((_args$ = args[0]) === null || _args$ === void 0 ? void 0 : _args$.patterns) || []), [defaultCopyPattern])
|
|
74
71
|
}];
|
|
75
72
|
});
|
|
76
|
-
|
|
73
|
+
var entrypoints = appContext.entrypoints;
|
|
74
|
+
var existNestedRoutes = entrypoints.some(function (entrypoint) {
|
|
75
|
+
return entrypoint.nestedRoutesEntry;
|
|
76
|
+
});
|
|
77
|
+
chain.plugin('route-plugin').use(RouterPlugin, [{
|
|
78
|
+
existNestedRoutes: existNestedRoutes
|
|
79
|
+
}]);
|
|
77
80
|
function isHtmlEnabled(config, target) {
|
|
78
81
|
var _config$tools;
|
|
79
|
-
|
|
80
82
|
return ((_config$tools = config.tools) === null || _config$tools === void 0 ? void 0 : _config$tools.htmlPlugin) !== false && target !== 'node' && target !== 'web-worker';
|
|
81
83
|
}
|
|
82
84
|
});
|
|
83
|
-
|
|
84
85
|
if (options) {
|
|
85
86
|
applyCallbacks(api, options);
|
|
86
87
|
}
|
|
87
88
|
}
|
|
88
89
|
};
|
|
89
90
|
};
|
|
91
|
+
|
|
90
92
|
/**
|
|
91
93
|
* register builder hooks callback
|
|
92
94
|
*/
|
|
93
|
-
|
|
94
95
|
function applyCallbacks(api, options) {
|
|
95
96
|
options.onAfterBuild && api.onAfterBuild(options.onAfterBuild);
|
|
96
97
|
options.onAfterCreateCompiler && api.onAfterCreateCompiler(options.onAfterCreateCompiler);
|
|
@@ -101,41 +102,36 @@ function applyCallbacks(api, options) {
|
|
|
101
102
|
options.onDevCompileDone && api.onDevCompileDone(options.onDevCompileDone);
|
|
102
103
|
options.onExit && api.onExit(options.onExit);
|
|
103
104
|
}
|
|
105
|
+
|
|
104
106
|
/**
|
|
105
107
|
* compat some config, if target is `node`
|
|
106
108
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
109
109
|
function applyNodeCompat(chain, modernConfig, isProd) {
|
|
110
110
|
// apply node resolve extensions
|
|
111
111
|
for (var _i = 0, _arr = ['.node.js', '.node.jsx', '.node.ts', '.node.tsx']; _i < _arr.length; _i++) {
|
|
112
112
|
var ext = _arr[_i];
|
|
113
113
|
chain.resolve.extensions.prepend(ext);
|
|
114
|
-
}
|
|
115
|
-
|
|
114
|
+
}
|
|
116
115
|
|
|
116
|
+
// apply filterEntriesBySSRConfig
|
|
117
117
|
filterEntriesBySSRConfig(isProd, chain, modernConfig.server, modernConfig.output);
|
|
118
|
-
|
|
119
118
|
function filterEntriesBySSRConfig(isProd, chain, serverConfig, outputConfig) {
|
|
120
119
|
var _outputConfig$ssg;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
120
|
+
var entries = chain.entryPoints.entries();
|
|
121
|
+
// if prod and ssg config is true or function
|
|
124
122
|
if (isProd && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof (outputConfig === null || outputConfig === void 0 ? void 0 : (_outputConfig$ssg = outputConfig.ssg) === null || _outputConfig$ssg === void 0 ? void 0 : _outputConfig$ssg[0]) === 'function')) {
|
|
125
123
|
return;
|
|
126
|
-
}
|
|
127
|
-
// `ssg: {}` is not allowed if multi entry
|
|
128
|
-
|
|
124
|
+
}
|
|
129
125
|
|
|
126
|
+
// if single entry has ssg config
|
|
127
|
+
// `ssg: {}` is not allowed if multi entry
|
|
130
128
|
var entryNames = Object.keys(entries);
|
|
131
|
-
|
|
132
129
|
if (isProd && entryNames.length === 1 && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
|
|
133
130
|
return;
|
|
134
|
-
}
|
|
135
|
-
|
|
131
|
+
}
|
|
136
132
|
|
|
133
|
+
// collect all ssg entries
|
|
137
134
|
var ssgEntries = [];
|
|
138
|
-
|
|
139
135
|
if (isProd && outputConfig !== null && outputConfig !== void 0 && outputConfig.ssg) {
|
|
140
136
|
var ssg = outputConfig.ssg;
|
|
141
137
|
entryNames.forEach(function (name) {
|
|
@@ -144,11 +140,9 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
144
140
|
}
|
|
145
141
|
});
|
|
146
142
|
}
|
|
147
|
-
|
|
148
143
|
var _ref2 = serverConfig || {},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
144
|
+
ssr = _ref2.ssr,
|
|
145
|
+
ssrByEntries = _ref2.ssrByEntries;
|
|
152
146
|
entryNames.forEach(function (name) {
|
|
153
147
|
if (!ssgEntries.includes(name) && (ssr && (ssrByEntries === null || ssrByEntries === void 0 ? void 0 : ssrByEntries[name]) === false || !ssr && !(ssrByEntries !== null && ssrByEntries !== void 0 && ssrByEntries[name]))) {
|
|
154
148
|
chain.entryPoints["delete"](name);
|
|
@@ -156,28 +150,24 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
156
150
|
});
|
|
157
151
|
}
|
|
158
152
|
}
|
|
153
|
+
|
|
159
154
|
/**
|
|
160
155
|
* inject bottom template
|
|
161
156
|
*/
|
|
162
|
-
|
|
163
|
-
|
|
164
157
|
function applyBottomHtmlWebpackPlugin(_ref3) {
|
|
165
158
|
var api = _ref3.api,
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
chain = _ref3.chain,
|
|
160
|
+
modernConfig = _ref3.modernConfig,
|
|
161
|
+
appContext = _ref3.appContext,
|
|
162
|
+
CHAIN_ID = _ref3.CHAIN_ID;
|
|
171
163
|
var _loop = function _loop() {
|
|
172
164
|
var entryName = _Object$keys[_i2];
|
|
173
|
-
|
|
174
165
|
// FIXME: the only need necessary
|
|
175
166
|
var baseTemplateParams = _objectSpread({
|
|
176
167
|
entryName: entryName,
|
|
177
168
|
title: getEntryOptions(entryName, modernConfig.output.title, modernConfig.output.titleByEntries, appContext.packageName),
|
|
178
169
|
mountId: modernConfig.output.mountId
|
|
179
170
|
}, getEntryOptions(entryName, modernConfig.output.templateParameters, modernConfig.output.templateParametersByEntries, appContext.packageName));
|
|
180
|
-
|
|
181
171
|
chain.plugin("".concat(CHAIN_ID.PLUGIN.HTML, "-").concat(entryName)).tap(function (args) {
|
|
182
172
|
return [_objectSpread(_objectSpread({}, args[0] || {}), {}, {
|
|
183
173
|
__internal__: true,
|
|
@@ -185,46 +175,37 @@ function applyBottomHtmlWebpackPlugin(_ref3) {
|
|
|
185
175
|
})];
|
|
186
176
|
});
|
|
187
177
|
};
|
|
188
|
-
|
|
189
178
|
// inject bottomTemplate into html-webpack-plugin
|
|
190
179
|
for (var _i2 = 0, _Object$keys = Object.keys(api.context.entry); _i2 < _Object$keys.length; _i2++) {
|
|
191
180
|
_loop();
|
|
192
181
|
}
|
|
193
|
-
|
|
194
182
|
chain.plugin(CHAIN_ID.PLUGIN.BOTTOM_TEMPLATE).use(BottomTemplatePlugin, [HtmlWebpackPlugin]);
|
|
195
183
|
}
|
|
196
|
-
|
|
197
184
|
var isStreamingSSR = function isStreamingSSR(userConfig) {
|
|
198
185
|
var isStreaming = function isStreaming(ssr) {
|
|
199
186
|
return ssr && _typeof(ssr) === 'object' && ssr.mode === 'stream';
|
|
200
187
|
};
|
|
201
|
-
|
|
202
188
|
var server = userConfig.server;
|
|
203
|
-
|
|
204
189
|
if (isStreaming(server.ssr)) {
|
|
205
190
|
return true;
|
|
206
|
-
}
|
|
207
|
-
// we regard the whole app as streaming ssr only if one entry meets the requirement.
|
|
208
|
-
|
|
191
|
+
}
|
|
209
192
|
|
|
193
|
+
// Since we cannot apply different plugins for different entries,
|
|
194
|
+
// we regard the whole app as streaming ssr only if one entry meets the requirement.
|
|
210
195
|
if (server !== null && server !== void 0 && server.ssrByEntries && _typeof(server.ssrByEntries) === 'object') {
|
|
211
196
|
for (var _i3 = 0, _Object$keys2 = Object.keys(server.ssrByEntries); _i3 < _Object$keys2.length; _i3++) {
|
|
212
197
|
var name = _Object$keys2[_i3];
|
|
213
|
-
|
|
214
198
|
if (isStreaming(server.ssrByEntries[name])) {
|
|
215
199
|
return true;
|
|
216
200
|
}
|
|
217
201
|
}
|
|
218
202
|
}
|
|
219
|
-
|
|
220
203
|
return false;
|
|
221
204
|
};
|
|
222
|
-
|
|
223
205
|
function applyAsyncChunkHtmlPlugin(_ref4) {
|
|
224
206
|
var chain = _ref4.chain,
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
207
|
+
modernConfig = _ref4.modernConfig,
|
|
208
|
+
CHAIN_ID = _ref4.CHAIN_ID;
|
|
228
209
|
if (isStreamingSSR(modernConfig)) {
|
|
229
210
|
chain.plugin(CHAIN_ID.PLUGIN.HTML_ASYNC_CHUNK).use(HtmlAsyncChunkPlugin, [HtmlWebpackPlugin]);
|
|
230
211
|
}
|
|
@@ -2,21 +2,22 @@ import path from 'path';
|
|
|
2
2
|
import { findExists } from '@modern-js/utils';
|
|
3
3
|
export function createHtmlConfig(normalizedConfig, appContext) {
|
|
4
4
|
var _normalizedConfig$out = normalizedConfig.output,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var configDir = normalizedConfig.source.configDir;
|
|
5
|
+
disableHtmlFolder = _normalizedConfig$out.disableHtmlFolder,
|
|
6
|
+
favicon = _normalizedConfig$out.favicon,
|
|
7
|
+
faviconByEntries = _normalizedConfig$out.faviconByEntries,
|
|
8
|
+
inject = _normalizedConfig$out.inject,
|
|
9
|
+
injectByEntries = _normalizedConfig$out.injectByEntries,
|
|
10
|
+
meta = _normalizedConfig$out.meta,
|
|
11
|
+
metaByEntries = _normalizedConfig$out.metaByEntries,
|
|
12
|
+
mountId = _normalizedConfig$out.mountId,
|
|
13
|
+
title = _normalizedConfig$out.title,
|
|
14
|
+
titleByEntries = _normalizedConfig$out.titleByEntries,
|
|
15
|
+
scriptExt = _normalizedConfig$out.scriptExt,
|
|
16
|
+
templateParameters = _normalizedConfig$out.templateParameters,
|
|
17
|
+
templateParametersByEntries = _normalizedConfig$out.templateParametersByEntries;
|
|
18
|
+
var configDir = normalizedConfig.source.configDir;
|
|
19
19
|
|
|
20
|
+
// transform Modernjs `output.scriptExt` to Builder `html.crossorigin` configuration
|
|
20
21
|
var builderCrossorigin = createBuilderCrossorigin(scriptExt);
|
|
21
22
|
var builderAppIcon = createBuilderAppIcon(configDir, appContext);
|
|
22
23
|
var builderFavicon = createBuilderFavicon(favicon, configDir, appContext);
|
|
@@ -47,7 +48,6 @@ export function createBuilderAppIcon(configDir, appContext) {
|
|
|
47
48
|
}
|
|
48
49
|
export function createBuilderCrossorigin(scriptExt) {
|
|
49
50
|
var _scriptExtCustomConfi;
|
|
50
|
-
|
|
51
51
|
var scriptExtCustomConfig = scriptExt === null || scriptExt === void 0 ? void 0 : scriptExt.custom;
|
|
52
52
|
return scriptExtCustomConfig !== null && scriptExtCustomConfig !== void 0 && (_scriptExtCustomConfi = scriptExtCustomConfig.test) !== null && _scriptExtCustomConfi !== void 0 && _scriptExtCustomConfi.test('.js') && (scriptExtCustomConfig === null || scriptExtCustomConfig === void 0 ? void 0 : scriptExtCustomConfig.attribute) === 'crossorigin' ? scriptExtCustomConfig.value : undefined;
|
|
53
53
|
}
|
|
@@ -2,26 +2,28 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
|
2
2
|
import { createCopyPattern } from "./share";
|
|
3
3
|
export function createOutputConfig(normalizedConfig, appContext) {
|
|
4
4
|
// TODO: add `externals` options in Modern.
|
|
5
|
+
|
|
5
6
|
var _normalizedConfig$out = normalizedConfig.output,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
7
|
+
assetPrefix = _normalizedConfig$out.assetPrefix,
|
|
8
|
+
copy = _normalizedConfig$out.copy,
|
|
9
|
+
cssModuleLocalIdentName = _normalizedConfig$out.cssModuleLocalIdentName,
|
|
10
|
+
cssPath = _normalizedConfig$out.cssPath,
|
|
11
|
+
jsPath = _normalizedConfig$out.jsPath,
|
|
12
|
+
htmlPath = _normalizedConfig$out.htmlPath,
|
|
13
|
+
mediaPath = _normalizedConfig$out.mediaPath,
|
|
14
|
+
path = _normalizedConfig$out.path,
|
|
15
|
+
disableInlineRuntimeChunk = _normalizedConfig$out.disableInlineRuntimeChunk,
|
|
16
|
+
disableMinimize = _normalizedConfig$out.disableMinimize,
|
|
17
|
+
disableSourceMap = _normalizedConfig$out.disableSourceMap,
|
|
18
|
+
disableTsChecker = _normalizedConfig$out.disableTsChecker,
|
|
19
|
+
enableCssModuleTSDeclaration = _normalizedConfig$out.enableCssModuleTSDeclaration,
|
|
20
|
+
enableInlineScripts = _normalizedConfig$out.enableInlineScripts,
|
|
21
|
+
enableInlineStyles = _normalizedConfig$out.enableInlineStyles,
|
|
22
|
+
polyfill = _normalizedConfig$out.polyfill,
|
|
23
|
+
dataUriLimit = _normalizedConfig$out.dataUriLimit,
|
|
24
|
+
disableAssetsCache = _normalizedConfig$out.disableAssetsCache,
|
|
25
|
+
enableLatestDecorators = _normalizedConfig$out.enableLatestDecorators,
|
|
26
|
+
disableCssModuleExtension = _normalizedConfig$out.disableCssModuleExtension;
|
|
25
27
|
var defaultCopyPattern = createCopyPattern(appContext, normalizedConfig, 'upload');
|
|
26
28
|
var builderCopy = copy ? [].concat(_toConsumableArray(copy), [defaultCopyPattern]) : [defaultCopyPattern];
|
|
27
29
|
return {
|
|
@@ -33,10 +35,10 @@ export function createOutputConfig(normalizedConfig, appContext) {
|
|
|
33
35
|
js: jsPath,
|
|
34
36
|
html: htmlPath,
|
|
35
37
|
// `@modern-js/webpack` output all media files to `dist/media` by default
|
|
36
|
-
svg: mediaPath || '
|
|
37
|
-
image: mediaPath || '
|
|
38
|
-
font: mediaPath || '
|
|
39
|
-
media: mediaPath || '
|
|
38
|
+
svg: mediaPath || 'media',
|
|
39
|
+
image: mediaPath || 'media',
|
|
40
|
+
font: mediaPath || 'media',
|
|
41
|
+
media: mediaPath || 'media'
|
|
40
42
|
},
|
|
41
43
|
dataUriLimit: {
|
|
42
44
|
svg: dataUriLimit,
|
|
@@ -48,6 +50,7 @@ export function createOutputConfig(normalizedConfig, appContext) {
|
|
|
48
50
|
disableInlineRuntimeChunk: disableInlineRuntimeChunk,
|
|
49
51
|
disableMinimize: disableMinimize,
|
|
50
52
|
disableSourceMap: disableSourceMap,
|
|
53
|
+
disableTsChecker: disableTsChecker,
|
|
51
54
|
enableCssModuleTSDeclaration: enableCssModuleTSDeclaration,
|
|
52
55
|
enableInlineScripts: enableInlineScripts,
|
|
53
56
|
enableInlineStyles: enableInlineStyles,
|