@modern-js/app-tools 1.21.2 → 2.0.0-beta.0
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 +139 -0
- package/dist/js/modern/analyze/constants.js +1 -0
- package/dist/js/modern/analyze/generateCode.js +118 -16
- package/dist/js/modern/analyze/getBundleEntry.js +3 -2
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +198 -0
- package/dist/js/modern/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +8 -28
- package/dist/js/modern/analyze/getClientRoutes/index.js +2 -0
- package/dist/js/modern/analyze/getClientRoutes/utils.js +21 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +31 -12
- package/dist/js/modern/analyze/index.js +2 -1
- package/dist/js/modern/analyze/nestedRoutes.js +127 -0
- package/dist/js/modern/analyze/templates.js +164 -10
- package/dist/js/modern/analyze/utils.js +2 -1
- package/dist/js/modern/builder/builderPlugins/compatModern.js +226 -0
- package/dist/js/modern/builder/createHtmlConfig.js +58 -0
- package/dist/js/modern/builder/createOutputConfig.js +67 -0
- package/dist/js/modern/builder/createSourceConfig.js +85 -0
- package/dist/js/modern/builder/createToolsConfig.js +94 -0
- package/dist/js/modern/builder/index.js +106 -0
- package/dist/js/modern/builder/share.js +48 -0
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +37 -0
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +44 -0
- package/dist/js/modern/commands/build.js +41 -95
- package/dist/js/modern/commands/dev.js +15 -19
- package/dist/js/modern/commands/inspect.js +17 -58
- package/dist/js/modern/commands/start.js +2 -1
- package/dist/js/modern/index.js +14 -4
- package/dist/js/modern/locale/en.js +0 -1
- package/dist/js/modern/locale/zh.js +0 -1
- package/dist/js/modern/utils/commands.js +5 -0
- package/dist/js/modern/utils/createCompiler.js +37 -40
- package/dist/js/modern/utils/createServer.js +16 -0
- package/dist/js/modern/utils/printInstructions.js +1 -1
- package/dist/js/node/analyze/constants.js +3 -1
- package/dist/js/node/analyze/generateCode.js +121 -14
- package/dist/js/node/analyze/getBundleEntry.js +3 -2
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +221 -0
- package/dist/js/node/analyze/{getClientRoutes.js → getClientRoutes/getRoutesLegacy.js} +16 -35
- package/dist/js/node/analyze/getClientRoutes/index.js +21 -0
- package/dist/js/node/analyze/getClientRoutes/utils.js +42 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +30 -11
- package/dist/js/node/analyze/index.js +2 -1
- package/dist/js/node/analyze/nestedRoutes.js +144 -0
- package/dist/js/node/analyze/templates.js +167 -10
- package/dist/js/node/analyze/utils.js +6 -2
- package/dist/js/node/builder/builderPlugins/compatModern.js +245 -0
- package/dist/js/node/builder/createHtmlConfig.js +76 -0
- package/dist/js/node/builder/createOutputConfig.js +75 -0
- package/dist/js/node/builder/createSourceConfig.js +99 -0
- package/dist/js/node/builder/createToolsConfig.js +103 -0
- package/dist/js/node/builder/index.js +129 -0
- package/dist/js/node/builder/share.js +63 -0
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +46 -0
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +53 -0
- package/dist/js/node/commands/build.js +44 -98
- package/dist/js/node/commands/dev.js +13 -23
- package/dist/js/node/commands/inspect.js +18 -74
- package/dist/js/node/commands/start.js +3 -1
- package/dist/js/node/index.js +19 -2
- package/dist/js/node/locale/en.js +0 -1
- package/dist/js/node/locale/zh.js +0 -1
- package/dist/js/node/utils/commands.js +14 -0
- package/dist/js/node/utils/createCompiler.js +43 -49
- package/dist/js/node/utils/createServer.js +21 -2
- package/dist/js/node/utils/printInstructions.js +1 -1
- package/dist/js/treeshaking/analyze/constants.js +16 -0
- package/dist/js/treeshaking/analyze/generateCode.js +412 -0
- package/dist/js/treeshaking/analyze/getBundleEntry.js +77 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +210 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +211 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +2 -0
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +27 -0
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +109 -0
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +153 -0
- package/dist/js/treeshaking/analyze/getServerRoutes.js +170 -0
- package/dist/js/treeshaking/analyze/index.js +214 -0
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +18 -0
- package/dist/js/treeshaking/analyze/nestedRoutes.js +207 -0
- package/dist/js/treeshaking/analyze/templates.js +189 -0
- package/dist/js/treeshaking/analyze/utils.js +95 -0
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +231 -0
- package/dist/js/treeshaking/builder/createHtmlConfig.js +59 -0
- package/dist/js/treeshaking/builder/createOutputConfig.js +67 -0
- package/dist/js/treeshaking/builder/createSourceConfig.js +100 -0
- package/dist/js/treeshaking/builder/createToolsConfig.js +90 -0
- package/dist/js/treeshaking/builder/index.js +172 -0
- package/dist/js/treeshaking/builder/share.js +50 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +58 -0
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +53 -0
- package/dist/js/treeshaking/commands/build.js +168 -0
- package/dist/js/treeshaking/commands/deploy.js +29 -0
- package/dist/js/treeshaking/commands/dev.js +146 -0
- package/dist/js/treeshaking/commands/index.js +3 -0
- package/dist/js/treeshaking/commands/inspect.js +52 -0
- package/dist/js/treeshaking/commands/start.js +78 -0
- package/dist/js/treeshaking/exports/server.js +1 -0
- package/dist/js/treeshaking/hooks.js +21 -0
- package/dist/js/treeshaking/index.js +304 -0
- package/dist/js/treeshaking/locale/en.js +34 -0
- package/dist/js/treeshaking/locale/index.js +9 -0
- package/dist/js/treeshaking/locale/zh.js +34 -0
- package/dist/js/treeshaking/utils/commands.js +5 -0
- package/dist/js/treeshaking/utils/config.js +140 -0
- package/dist/js/treeshaking/utils/createCompiler.js +117 -0
- package/dist/js/treeshaking/utils/createServer.js +83 -0
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +68 -0
- package/dist/js/treeshaking/utils/language.js +5 -0
- package/dist/js/treeshaking/utils/printInstructions.js +35 -0
- package/dist/js/treeshaking/utils/routes.js +33 -0
- package/dist/js/treeshaking/utils/types.js +0 -0
- package/dist/types/analyze/constants.d.ts +1 -0
- package/dist/types/analyze/generateCode.d.ts +1 -1
- package/dist/types/analyze/{getClientRoutes.d.ts → getClientRoutes/getRoutes.d.ts} +2 -7
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +15 -0
- package/dist/types/analyze/getClientRoutes/index.d.ts +2 -0
- package/dist/types/analyze/getClientRoutes/utils.d.ts +5 -0
- package/dist/types/analyze/index.d.ts +2 -2
- package/dist/types/analyze/nestedRoutes.d.ts +5 -0
- package/dist/types/analyze/templates.d.ts +17 -3
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +14 -0
- package/dist/types/builder/createHtmlConfig.d.ts +6 -0
- package/dist/types/builder/createOutputConfig.d.ts +3 -0
- package/dist/types/builder/createSourceConfig.d.ts +5 -0
- package/dist/types/builder/createToolsConfig.d.ts +13 -0
- package/dist/types/builder/index.d.ts +19 -0
- package/dist/types/builder/share.d.ts +26 -0
- package/dist/types/builder/webpackPlugins/htmlAsyncChunkPlugin.d.ts +8 -0
- package/dist/types/builder/webpackPlugins/htmlBottomTemplate.d.ts +10 -0
- package/dist/types/commands/build.d.ts +2 -1
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/commands/dev.d.ts +2 -1
- package/dist/types/commands/inspect.d.ts +5 -6
- package/dist/types/commands/start.d.ts +2 -1
- package/dist/types/hooks.d.ts +15 -10
- package/dist/types/index.d.ts +4 -2
- package/dist/types/locale/en.d.ts +0 -1
- package/dist/types/locale/index.d.ts +0 -2
- package/dist/types/locale/zh.d.ts +0 -1
- package/dist/types/utils/commands.d.ts +1 -0
- package/dist/types/utils/createCompiler.d.ts +9 -10
- package/dist/types/utils/createServer.d.ts +8 -1
- package/dist/types/utils/printInstructions.d.ts +3 -2
- package/dist/types/utils/types.d.ts +2 -3
- package/package.json +25 -43
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import { createBuilder } from '@modern-js/builder';
|
|
5
|
+
import { builderWebpackProvider } from '@modern-js/builder-webpack-provider';
|
|
6
|
+
import { applyOptionsChain } from '@modern-js/utils';
|
|
7
|
+
import { PluginCompatModern } from "./builderPlugins/compatModern";
|
|
8
|
+
import { createHtmlConfig } from "./createHtmlConfig";
|
|
9
|
+
import { createOutputConfig } from "./createOutputConfig";
|
|
10
|
+
import { createSourceConfig } from "./createSourceConfig";
|
|
11
|
+
import { createToolsConfig } from "./createToolsConfig";
|
|
12
|
+
export default /*#__PURE__*/(function () {
|
|
13
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref) {
|
|
14
|
+
var _ref$target, target, normalizedConfig, appContext, compatPluginConfig, targets, builderConfig, webpackProvider, builderOptions, builder;
|
|
15
|
+
|
|
16
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
17
|
+
while (1) {
|
|
18
|
+
switch (_context.prev = _context.next) {
|
|
19
|
+
case 0:
|
|
20
|
+
_ref$target = _ref.target, target = _ref$target === void 0 ? 'web' : _ref$target, normalizedConfig = _ref.normalizedConfig, appContext = _ref.appContext, compatPluginConfig = _ref.compatPluginConfig;
|
|
21
|
+
targets = Array.isArray(target) ? target : [target];
|
|
22
|
+
|
|
23
|
+
if (normalizedConfig.output.enableModernMode && !targets.includes('modern-web')) {
|
|
24
|
+
targets.push('modern-web');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
builderConfig = createBuilderProviderConfig(normalizedConfig, appContext); // create webpack provider
|
|
28
|
+
|
|
29
|
+
webpackProvider = builderWebpackProvider({
|
|
30
|
+
builderConfig: builderConfig
|
|
31
|
+
});
|
|
32
|
+
builderOptions = createBuilderOptions(target, appContext);
|
|
33
|
+
_context.next = 8;
|
|
34
|
+
return createBuilder(webpackProvider, builderOptions);
|
|
35
|
+
|
|
36
|
+
case 8:
|
|
37
|
+
builder = _context.sent;
|
|
38
|
+
_context.next = 11;
|
|
39
|
+
return applyBuilderPlugins(builder, normalizedConfig, appContext, compatPluginConfig);
|
|
40
|
+
|
|
41
|
+
case 11:
|
|
42
|
+
return _context.abrupt("return", builder);
|
|
43
|
+
|
|
44
|
+
case 12:
|
|
45
|
+
case "end":
|
|
46
|
+
return _context.stop();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}, _callee);
|
|
50
|
+
}));
|
|
51
|
+
|
|
52
|
+
return function (_x) {
|
|
53
|
+
return _ref2.apply(this, arguments);
|
|
54
|
+
};
|
|
55
|
+
})();
|
|
56
|
+
|
|
57
|
+
function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
58
|
+
var source = createSourceConfig(normalizedConfig, appContext);
|
|
59
|
+
var html = createHtmlConfig(normalizedConfig, appContext);
|
|
60
|
+
var output = createOutputConfig(normalizedConfig, appContext);
|
|
61
|
+
var tools = createToolsConfig(normalizedConfig);
|
|
62
|
+
return {
|
|
63
|
+
source: source,
|
|
64
|
+
html: html,
|
|
65
|
+
output: output,
|
|
66
|
+
tools: tools,
|
|
67
|
+
performance: {
|
|
68
|
+
// `@modern-js/webpack` used to remove moment locale by default
|
|
69
|
+
removeMomentLocale: true
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function createBuilderOptions(target, appContext) {
|
|
75
|
+
// create entries
|
|
76
|
+
var entries = {};
|
|
77
|
+
var _appContext$entrypoin = appContext.entrypoints,
|
|
78
|
+
entrypoints = _appContext$entrypoin === void 0 ? [] : _appContext$entrypoin,
|
|
79
|
+
checkedEntries = appContext.checkedEntries;
|
|
80
|
+
|
|
81
|
+
var _iterator = _createForOfIteratorHelper(entrypoints),
|
|
82
|
+
_step;
|
|
83
|
+
|
|
84
|
+
try {
|
|
85
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
86
|
+
var _step$value = _step.value,
|
|
87
|
+
entryName = _step$value.entryName,
|
|
88
|
+
entry = _step$value.entry;
|
|
89
|
+
|
|
90
|
+
if (checkedEntries && !checkedEntries.includes(entryName)) {
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (entryName in entries) {
|
|
95
|
+
entries[entryName].push(entry);
|
|
96
|
+
} else {
|
|
97
|
+
entries[entryName] = [entry];
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} catch (err) {
|
|
101
|
+
_iterator.e(err);
|
|
102
|
+
} finally {
|
|
103
|
+
_iterator.f();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
cwd: appContext.appDirectory,
|
|
108
|
+
target: target,
|
|
109
|
+
configPath: appContext.configFile || undefined,
|
|
110
|
+
entry: entries,
|
|
111
|
+
framework: appContext.metaName
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* register builder Plugin by condition
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
function applyBuilderPlugins(_x2, _x3, _x4, _x5) {
|
|
119
|
+
return _applyBuilderPlugins.apply(this, arguments);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
function _applyBuilderPlugins() {
|
|
123
|
+
_applyBuilderPlugins = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(builder, normalizedConfig, appContext, compatPluginConfig) {
|
|
124
|
+
var _yield$import, PluginNodePolyfill, esbuildOptions, _yield$import2, PluginEsbuild;
|
|
125
|
+
|
|
126
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
127
|
+
while (1) {
|
|
128
|
+
switch (_context2.prev = _context2.next) {
|
|
129
|
+
case 0:
|
|
130
|
+
if (normalizedConfig.output.disableNodePolyfill) {
|
|
131
|
+
_context2.next = 6;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
_context2.next = 3;
|
|
136
|
+
return import('@modern-js/builder-plugin-node-polyfill');
|
|
137
|
+
|
|
138
|
+
case 3:
|
|
139
|
+
_yield$import = _context2.sent;
|
|
140
|
+
PluginNodePolyfill = _yield$import.PluginNodePolyfill;
|
|
141
|
+
builder.addPlugins([PluginNodePolyfill()]);
|
|
142
|
+
|
|
143
|
+
case 6:
|
|
144
|
+
if (!normalizedConfig.tools.esbuild) {
|
|
145
|
+
_context2.next = 13;
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
esbuildOptions = normalizedConfig.tools.esbuild;
|
|
150
|
+
_context2.next = 10;
|
|
151
|
+
return import('@modern-js/builder-plugin-esbuild');
|
|
152
|
+
|
|
153
|
+
case 10:
|
|
154
|
+
_yield$import2 = _context2.sent;
|
|
155
|
+
PluginEsbuild = _yield$import2.PluginEsbuild;
|
|
156
|
+
builder.addPlugins([PluginEsbuild({
|
|
157
|
+
loader: false,
|
|
158
|
+
minimize: applyOptionsChain({}, esbuildOptions)
|
|
159
|
+
})]);
|
|
160
|
+
|
|
161
|
+
case 13:
|
|
162
|
+
builder.addPlugins([PluginCompatModern(appContext, normalizedConfig, compatPluginConfig)]);
|
|
163
|
+
|
|
164
|
+
case 14:
|
|
165
|
+
case "end":
|
|
166
|
+
return _context2.stop();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, _callee2);
|
|
170
|
+
}));
|
|
171
|
+
return _applyBuilderPlugins.apply(this, arguments);
|
|
172
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import path from 'path';
|
|
2
|
+
import { template as lodashTemplate } from '@modern-js/utils/lodash';
|
|
3
|
+
import { removeTailSlash } from '@modern-js/utils';
|
|
4
|
+
export function createCopyPattern(appContext, config, patternsType, chain) {
|
|
5
|
+
var configDir = path.resolve(appContext.appDirectory, config.source.configDir);
|
|
6
|
+
var uploadDir = path.posix.join(configDir.replace(/\\/g, '/'), 'upload');
|
|
7
|
+
var publicDir = path.posix.join(configDir.replace(/\\/g, '/'), 'public');
|
|
8
|
+
var minifiedJsRexExp = /\.min\.js/;
|
|
9
|
+
|
|
10
|
+
var info = function info(file) {
|
|
11
|
+
return {
|
|
12
|
+
// If the file name ends with `.min.js`, we assume it's a compressed file.
|
|
13
|
+
// So we don't want copy-webpack-plugin to minify it.
|
|
14
|
+
// ref: https://github.com/webpack-contrib/copy-webpack-plugin#info
|
|
15
|
+
minimized: minifiedJsRexExp.test(file.sourceFilename)
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
if (patternsType === 'public') {
|
|
20
|
+
if (!chain) {
|
|
21
|
+
throw new Error("expect get a webpackChain, but receive 'undefined'");
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return {
|
|
25
|
+
info: info,
|
|
26
|
+
from: '**/*',
|
|
27
|
+
to: 'public',
|
|
28
|
+
context: publicDir,
|
|
29
|
+
noErrorOnMissing: true,
|
|
30
|
+
// eslint-disable-next-line node/prefer-global/buffer
|
|
31
|
+
transform: function transform(content, absoluteFrom) {
|
|
32
|
+
if (!/\.html?$/.test(absoluteFrom)) {
|
|
33
|
+
return content;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return lodashTemplate(content.toString('utf8'))({
|
|
37
|
+
assetPrefix: removeTailSlash(chain.output.get('publicPath'))
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
} else {
|
|
42
|
+
return {
|
|
43
|
+
info: info,
|
|
44
|
+
from: '**/*',
|
|
45
|
+
to: 'upload',
|
|
46
|
+
context: uploadDir,
|
|
47
|
+
noErrorOnMissing: true
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
5
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
6
|
+
export var HtmlAsyncChunkPlugin = /*#__PURE__*/function () {
|
|
7
|
+
function HtmlAsyncChunkPlugin(htmlWebpackPlugin) {
|
|
8
|
+
_classCallCheck(this, HtmlAsyncChunkPlugin);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "name", void 0);
|
|
11
|
+
|
|
12
|
+
_defineProperty(this, "htmlWebpackPlugin", void 0);
|
|
13
|
+
|
|
14
|
+
this.name = 'HtmlAsyncChunkPlugin';
|
|
15
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_createClass(HtmlAsyncChunkPlugin, [{
|
|
19
|
+
key: "apply",
|
|
20
|
+
value: function apply(compiler) {
|
|
21
|
+
var _this = this;
|
|
22
|
+
|
|
23
|
+
compiler.hooks.compilation.tap(this.name, function (compilation) {
|
|
24
|
+
var hooks = _this.htmlWebpackPlugin.getHooks(compilation);
|
|
25
|
+
|
|
26
|
+
hooks.alterAssetTagGroups.tap(_this.name, function (assets) {
|
|
27
|
+
var tags = [].concat(_toConsumableArray(assets.headTags), _toConsumableArray(assets.bodyTags));
|
|
28
|
+
|
|
29
|
+
var _iterator = _createForOfIteratorHelper(tags),
|
|
30
|
+
_step;
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
34
|
+
var tag = _step.value;
|
|
35
|
+
|
|
36
|
+
if (tag.tagName === 'script') {
|
|
37
|
+
var attributes = tag.attributes;
|
|
38
|
+
|
|
39
|
+
if (attributes && attributes.defer === true) {
|
|
40
|
+
attributes.async = true;
|
|
41
|
+
delete attributes.defer;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
} catch (err) {
|
|
46
|
+
_iterator.e(err);
|
|
47
|
+
} finally {
|
|
48
|
+
_iterator.f();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return assets;
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}]);
|
|
56
|
+
|
|
57
|
+
return HtmlAsyncChunkPlugin;
|
|
58
|
+
}();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
|
+
export var BottomTemplatePlugin = /*#__PURE__*/function () {
|
|
5
|
+
function BottomTemplatePlugin(htmlWebpackPlugin) {
|
|
6
|
+
_classCallCheck(this, BottomTemplatePlugin);
|
|
7
|
+
|
|
8
|
+
_defineProperty(this, "htmlWebpackPlugin", void 0);
|
|
9
|
+
|
|
10
|
+
_defineProperty(this, "bottomTemplateReg", /<!--<\?-\s*bottomTemplate\s*\?>-->/);
|
|
11
|
+
|
|
12
|
+
_defineProperty(this, "bodyRegExp", /(<\/\s*body\s*>)/i);
|
|
13
|
+
|
|
14
|
+
_defineProperty(this, "name", void 0);
|
|
15
|
+
|
|
16
|
+
this.htmlWebpackPlugin = htmlWebpackPlugin;
|
|
17
|
+
this.name = 'bottom-template';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
_createClass(BottomTemplatePlugin, [{
|
|
21
|
+
key: "apply",
|
|
22
|
+
value: function apply(compiler) {
|
|
23
|
+
var _this = this;
|
|
24
|
+
|
|
25
|
+
compiler.hooks.compilation.tap(this.name, function (compilation) {
|
|
26
|
+
_this.htmlWebpackPlugin.getHooks(compilation).beforeEmit.tap(_this.name, function (data) {
|
|
27
|
+
var _data$plugin$options;
|
|
28
|
+
|
|
29
|
+
if (!((_data$plugin$options = data.plugin.options) !== null && _data$plugin$options !== void 0 && _data$plugin$options.__internal__)) {
|
|
30
|
+
return data;
|
|
31
|
+
} // 含有 <!--<?- bottomTemplate ?>--> 占位符时才需要注入 bottom.html
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
if (_this.bottomTemplateReg.test(data.html)) {
|
|
35
|
+
// 清空占位符
|
|
36
|
+
data.html = data.html.replace(_this.bottomTemplateReg, '');
|
|
37
|
+
var bottomTemplate = data.plugin.options.bottomTemplate;
|
|
38
|
+
|
|
39
|
+
if (bottomTemplate) {
|
|
40
|
+
data.html = data.html.replace(_this.bodyRegExp, function (match) {
|
|
41
|
+
return "\n".concat(bottomTemplate, "\n").concat(match);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return data;
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}]);
|
|
51
|
+
|
|
52
|
+
return BottomTemplatePlugin;
|
|
53
|
+
}();
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import { ResolvedConfigContext } from '@modern-js/core';
|
|
5
|
+
import { logger, isUseSSRBundle, printBuildError } from '@modern-js/utils';
|
|
6
|
+
import { generateRoutes } from "../utils/routes";
|
|
7
|
+
import { buildServerConfig, emitResolvedConfig } from "../utils/config";
|
|
8
|
+
import createBuilder from "../builder";
|
|
9
|
+
export var build = /*#__PURE__*/function () {
|
|
10
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(api, options) {
|
|
11
|
+
var resolvedConfig, appContext, hookRunners, apiOnly, _appDirectory, _distDirectory, _serverConfigFile, distDirectory, appDirectory, serverConfigFile, targets, builder;
|
|
12
|
+
|
|
13
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
14
|
+
while (1) {
|
|
15
|
+
switch (_context3.prev = _context3.next) {
|
|
16
|
+
case 0:
|
|
17
|
+
resolvedConfig = api.useResolvedConfigContext();
|
|
18
|
+
appContext = api.useAppContext();
|
|
19
|
+
hookRunners = api.useHookRunners();
|
|
20
|
+
apiOnly = appContext.apiOnly;
|
|
21
|
+
|
|
22
|
+
if (!apiOnly) {
|
|
23
|
+
_context3.next = 15;
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_appDirectory = appContext.appDirectory, _distDirectory = appContext.distDirectory, _serverConfigFile = appContext.serverConfigFile;
|
|
28
|
+
_context3.next = 8;
|
|
29
|
+
return hookRunners.beforeBuild({
|
|
30
|
+
// "null" bundlerConfigs
|
|
31
|
+
bundlerConfigs: undefined
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
case 8:
|
|
35
|
+
_context3.next = 10;
|
|
36
|
+
return buildServerConfig({
|
|
37
|
+
appDirectory: _appDirectory,
|
|
38
|
+
distDirectory: _distDirectory,
|
|
39
|
+
configFile: _serverConfigFile
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
case 10:
|
|
43
|
+
_context3.next = 12;
|
|
44
|
+
return generateRoutes(appContext);
|
|
45
|
+
|
|
46
|
+
case 12:
|
|
47
|
+
_context3.next = 14;
|
|
48
|
+
return hookRunners.afterBuild({
|
|
49
|
+
// "null" stats
|
|
50
|
+
stats: undefined
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
case 14:
|
|
54
|
+
return _context3.abrupt("return");
|
|
55
|
+
|
|
56
|
+
case 15:
|
|
57
|
+
resolvedConfig = _objectSpread(_objectSpread({}, resolvedConfig), {}, {
|
|
58
|
+
cliOptions: options
|
|
59
|
+
});
|
|
60
|
+
ResolvedConfigContext.set(resolvedConfig);
|
|
61
|
+
distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, serverConfigFile = appContext.serverConfigFile;
|
|
62
|
+
_context3.next = 20;
|
|
63
|
+
return buildServerConfig({
|
|
64
|
+
appDirectory: appDirectory,
|
|
65
|
+
distDirectory: distDirectory,
|
|
66
|
+
configFile: serverConfigFile
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
case 20:
|
|
70
|
+
targets = ['web'];
|
|
71
|
+
|
|
72
|
+
if (resolvedConfig.output.enableModernMode) {
|
|
73
|
+
targets.push('modern-web');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isUseSSRBundle(resolvedConfig)) {
|
|
77
|
+
targets.push('node');
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
_context3.prev = 23;
|
|
81
|
+
_context3.next = 26;
|
|
82
|
+
return createBuilder({
|
|
83
|
+
target: targets,
|
|
84
|
+
appContext: appContext,
|
|
85
|
+
normalizedConfig: resolvedConfig,
|
|
86
|
+
compatPluginConfig: {
|
|
87
|
+
onBeforeBuild: function onBeforeBuild(_ref2) {
|
|
88
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
89
|
+
var bundlerConfigs;
|
|
90
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
91
|
+
while (1) {
|
|
92
|
+
switch (_context.prev = _context.next) {
|
|
93
|
+
case 0:
|
|
94
|
+
bundlerConfigs = _ref2.bundlerConfigs;
|
|
95
|
+
_context.next = 3;
|
|
96
|
+
return generateRoutes(appContext);
|
|
97
|
+
|
|
98
|
+
case 3:
|
|
99
|
+
_context.next = 5;
|
|
100
|
+
return hookRunners.beforeBuild({
|
|
101
|
+
bundlerConfigs: bundlerConfigs
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
case 5:
|
|
105
|
+
case "end":
|
|
106
|
+
return _context.stop();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}, _callee);
|
|
110
|
+
}))();
|
|
111
|
+
},
|
|
112
|
+
onAfterBuild: function onAfterBuild(_ref3) {
|
|
113
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
114
|
+
var stats;
|
|
115
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
116
|
+
while (1) {
|
|
117
|
+
switch (_context2.prev = _context2.next) {
|
|
118
|
+
case 0:
|
|
119
|
+
stats = _ref3.stats;
|
|
120
|
+
_context2.next = 3;
|
|
121
|
+
return hookRunners.afterBuild({
|
|
122
|
+
stats: stats
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
case 3:
|
|
126
|
+
_context2.next = 5;
|
|
127
|
+
return emitResolvedConfig(appDirectory, resolvedConfig);
|
|
128
|
+
|
|
129
|
+
case 5:
|
|
130
|
+
case "end":
|
|
131
|
+
return _context2.stop();
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}, _callee2);
|
|
135
|
+
}))();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
case 26:
|
|
141
|
+
builder = _context3.sent;
|
|
142
|
+
logger.info('Create a production build...\n');
|
|
143
|
+
_context3.next = 30;
|
|
144
|
+
return builder.build();
|
|
145
|
+
|
|
146
|
+
case 30:
|
|
147
|
+
_context3.next = 36;
|
|
148
|
+
break;
|
|
149
|
+
|
|
150
|
+
case 32:
|
|
151
|
+
_context3.prev = 32;
|
|
152
|
+
_context3.t0 = _context3["catch"](23);
|
|
153
|
+
printBuildError(_context3.t0); // eslint-disable-next-line no-process-exit
|
|
154
|
+
|
|
155
|
+
process.exit(1);
|
|
156
|
+
|
|
157
|
+
case 36:
|
|
158
|
+
case "end":
|
|
159
|
+
return _context3.stop();
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}, _callee3, null, [[23, 32]]);
|
|
163
|
+
}));
|
|
164
|
+
|
|
165
|
+
return function build(_x, _x2) {
|
|
166
|
+
return _ref.apply(this, arguments);
|
|
167
|
+
};
|
|
168
|
+
}();
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
3
|
+
export var deploy = /*#__PURE__*/function () {
|
|
4
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(api, options) {
|
|
5
|
+
var hookRunners;
|
|
6
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
7
|
+
while (1) {
|
|
8
|
+
switch (_context.prev = _context.next) {
|
|
9
|
+
case 0:
|
|
10
|
+
hookRunners = api.useHookRunners();
|
|
11
|
+
_context.next = 3;
|
|
12
|
+
return hookRunners.beforeDeploy(options);
|
|
13
|
+
|
|
14
|
+
case 3:
|
|
15
|
+
_context.next = 5;
|
|
16
|
+
return hookRunners.afterDeploy(options);
|
|
17
|
+
|
|
18
|
+
case 5:
|
|
19
|
+
case "end":
|
|
20
|
+
return _context.stop();
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}, _callee);
|
|
24
|
+
}));
|
|
25
|
+
|
|
26
|
+
return function deploy(_x, _x2) {
|
|
27
|
+
return _ref.apply(this, arguments);
|
|
28
|
+
};
|
|
29
|
+
}();
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import _regeneratorRuntime from "@babel/runtime/helpers/esm/regeneratorRuntime";
|
|
2
|
+
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
3
|
+
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
4
|
+
import { logger, isSSR } from '@modern-js/utils';
|
|
5
|
+
import { ResolvedConfigContext } from '@modern-js/core';
|
|
6
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
7
|
+
import { createDevCompiler } from "../utils/createCompiler";
|
|
8
|
+
import { createServer, injectDataLoaderPlugin } from "../utils/createServer";
|
|
9
|
+
import { generateRoutes } from "../utils/routes";
|
|
10
|
+
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
11
|
+
import { buildServerConfig } from "../utils/config";
|
|
12
|
+
export var dev = /*#__PURE__*/function () {
|
|
13
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(api, options) {
|
|
14
|
+
var userConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, entrypoints, serverConfigFile, serverInternalPlugins, checkedEntries, compiler, target, app;
|
|
15
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
16
|
+
while (1) {
|
|
17
|
+
switch (_context2.prev = _context2.next) {
|
|
18
|
+
case 0:
|
|
19
|
+
userConfig = api.useResolvedConfigContext();
|
|
20
|
+
appContext = api.useAppContext();
|
|
21
|
+
hookRunners = api.useHookRunners();
|
|
22
|
+
userConfig = _objectSpread(_objectSpread({}, userConfig), {}, {
|
|
23
|
+
cliOptions: options
|
|
24
|
+
});
|
|
25
|
+
ResolvedConfigContext.set(userConfig);
|
|
26
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, entrypoints = appContext.entrypoints, serverConfigFile = appContext.serverConfigFile, serverInternalPlugins = appContext.serverInternalPlugins;
|
|
27
|
+
_context2.next = 8;
|
|
28
|
+
return getSpecifiedEntries(options.entry || false, entrypoints);
|
|
29
|
+
|
|
30
|
+
case 8:
|
|
31
|
+
checkedEntries = _context2.sent;
|
|
32
|
+
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
|
33
|
+
checkedEntries: checkedEntries
|
|
34
|
+
}));
|
|
35
|
+
appContext.checkedEntries = checkedEntries;
|
|
36
|
+
_context2.next = 13;
|
|
37
|
+
return buildServerConfig({
|
|
38
|
+
appDirectory: appDirectory,
|
|
39
|
+
distDirectory: distDirectory,
|
|
40
|
+
configFile: serverConfigFile,
|
|
41
|
+
options: {
|
|
42
|
+
esbuildOptions: {
|
|
43
|
+
watch: true
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
case 13:
|
|
49
|
+
_context2.next = 15;
|
|
50
|
+
return hookRunners.beforeDev();
|
|
51
|
+
|
|
52
|
+
case 15:
|
|
53
|
+
compiler = null;
|
|
54
|
+
|
|
55
|
+
if (apiOnly) {
|
|
56
|
+
_context2.next = 21;
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
target = isSSR(userConfig) ? ['web', 'node'] : ['web'];
|
|
61
|
+
_context2.next = 20;
|
|
62
|
+
return createDevCompiler({
|
|
63
|
+
target: target,
|
|
64
|
+
api: api,
|
|
65
|
+
normalizedConfig: userConfig,
|
|
66
|
+
appContext: appContext
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
case 20:
|
|
70
|
+
compiler = _context2.sent;
|
|
71
|
+
|
|
72
|
+
case 21:
|
|
73
|
+
_context2.next = 23;
|
|
74
|
+
return generateRoutes(appContext);
|
|
75
|
+
|
|
76
|
+
case 23:
|
|
77
|
+
_context2.next = 25;
|
|
78
|
+
return createServer({
|
|
79
|
+
dev: _objectSpread(_objectSpread({}, {
|
|
80
|
+
client: {
|
|
81
|
+
port: port.toString()
|
|
82
|
+
},
|
|
83
|
+
devMiddleware: {
|
|
84
|
+
writeToDisk: function writeToDisk(file) {
|
|
85
|
+
return !file.includes('.hot-update.');
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
hot: true,
|
|
89
|
+
liveReload: true,
|
|
90
|
+
port: port,
|
|
91
|
+
https: userConfig.dev.https
|
|
92
|
+
}), userConfig.tools.devServer),
|
|
93
|
+
compiler: compiler,
|
|
94
|
+
pwd: appDirectory,
|
|
95
|
+
config: userConfig,
|
|
96
|
+
serverConfigFile: serverConfigFile,
|
|
97
|
+
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
case 25:
|
|
101
|
+
app = _context2.sent;
|
|
102
|
+
app.listen(port, /*#__PURE__*/function () {
|
|
103
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(err) {
|
|
104
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
105
|
+
while (1) {
|
|
106
|
+
switch (_context.prev = _context.next) {
|
|
107
|
+
case 0:
|
|
108
|
+
if (!err) {
|
|
109
|
+
_context.next = 2;
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
throw err;
|
|
114
|
+
|
|
115
|
+
case 2:
|
|
116
|
+
if (!apiOnly) {
|
|
117
|
+
logger.info("Starting dev server...");
|
|
118
|
+
} else {
|
|
119
|
+
printInstructions(hookRunners, appContext, userConfig);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
case 3:
|
|
123
|
+
case "end":
|
|
124
|
+
return _context.stop();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}, _callee);
|
|
128
|
+
}));
|
|
129
|
+
|
|
130
|
+
return function (_x3) {
|
|
131
|
+
return _ref2.apply(this, arguments);
|
|
132
|
+
};
|
|
133
|
+
}());
|
|
134
|
+
|
|
135
|
+
case 27:
|
|
136
|
+
case "end":
|
|
137
|
+
return _context2.stop();
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}, _callee2);
|
|
141
|
+
}));
|
|
142
|
+
|
|
143
|
+
return function dev(_x, _x2) {
|
|
144
|
+
return _ref.apply(this, arguments);
|
|
145
|
+
};
|
|
146
|
+
}();
|