@modern-js/app-tools 2.60.2 → 2.60.3
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/builder/builder-rspack/index.js +0 -4
- package/dist/cjs/builder/builder-webpack/index.js +0 -4
- package/dist/cjs/builder/{builder-webpack/adapterModern.js → generator/adapterCopy.js} +8 -8
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +1 -1
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +10 -2
- package/dist/cjs/builder/generator/index.js +8 -2
- package/dist/cjs/index.js +11 -1
- package/dist/cjs/utils/register.js +2 -1
- package/dist/esm/builder/builder-rspack/index.js +0 -4
- package/dist/esm/builder/builder-webpack/index.js +0 -4
- package/dist/esm/builder/{builder-webpack/adapterModern.js → generator/adapterCopy.js} +4 -4
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +1 -1
- package/dist/esm/builder/generator/getBuilderEnvironments.js +10 -2
- package/dist/esm/builder/generator/index.js +9 -3
- package/dist/esm/index.js +15 -2
- package/dist/esm/utils/register.js +3 -2
- package/dist/esm-node/builder/builder-rspack/index.js +0 -4
- package/dist/esm-node/builder/builder-webpack/index.js +0 -4
- package/dist/esm-node/builder/{builder-webpack/adapterModern.js → generator/adapterCopy.js} +4 -4
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +1 -1
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +10 -2
- package/dist/esm-node/builder/generator/index.js +8 -2
- package/dist/esm-node/index.js +11 -1
- package/dist/esm-node/utils/register.js +3 -2
- package/dist/types/builder/generator/adapterCopy.d.ts +3 -0
- package/dist/types/builder/generator/getBuilderEnvironments.d.ts +6 -3
- package/package.json +20 -20
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +0 -101
- package/dist/esm/builder/builder-rspack/adapterCopy.js +0 -166
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +0 -67
- package/dist/types/builder/builder-rspack/adapterCopy.d.ts +0 -3
- package/dist/types/builder/builder-webpack/adapterModern.d.ts +0 -6
- /package/dist/cjs/builder/{builder-webpack → generator}/createCopyPattern.js +0 -0
- /package/dist/esm/builder/{builder-webpack → generator}/createCopyPattern.js +0 -0
- /package/dist/esm-node/builder/{builder-webpack → generator}/createCopyPattern.js +0 -0
- /package/dist/types/builder/{builder-webpack → generator}/createCopyPattern.d.ts +0 -0
@@ -22,12 +22,8 @@ __export(builder_rspack_exports, {
|
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(builder_rspack_exports);
|
24
24
|
var import_generator = require("../generator");
|
25
|
-
var import_adapterCopy = require("./adapterCopy");
|
26
25
|
async function createRspackBuilderForModern(options) {
|
27
26
|
const builder = await (0, import_generator.generateBuilder)(options, "rspack");
|
28
|
-
builder.addPlugins([
|
29
|
-
(0, import_adapterCopy.builderPluginAdpaterCopy)(options)
|
30
|
-
]);
|
31
27
|
return builder;
|
32
28
|
}
|
33
29
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -32,7 +32,6 @@ __export(builder_webpack_exports, {
|
|
32
32
|
});
|
33
33
|
module.exports = __toCommonJS(builder_webpack_exports);
|
34
34
|
var import_generator = require("../generator");
|
35
|
-
var import_adapterModern = require("./adapterModern");
|
36
35
|
async function createWebpackBuilderForModern(options) {
|
37
36
|
const builder = await (0, import_generator.generateBuilder)(options, "webpack");
|
38
37
|
const { normalizedConfig } = options;
|
@@ -43,9 +42,6 @@ async function createWebpackBuilderForModern(options) {
|
|
43
42
|
pluginEsbuild(esbuildOptions)
|
44
43
|
]);
|
45
44
|
}
|
46
|
-
builder.addPlugins([
|
47
|
-
(0, import_adapterModern.builderPluginAdapterModern)(options)
|
48
|
-
]);
|
49
45
|
return builder;
|
50
46
|
}
|
51
47
|
// Annotate the CommonJS export names for ESM import in node:
|
@@ -16,17 +16,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
16
16
|
return to;
|
17
17
|
};
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var
|
20
|
-
__export(
|
21
|
-
|
19
|
+
var adapterCopy_exports = {};
|
20
|
+
__export(adapterCopy_exports, {
|
21
|
+
builderPluginAdapterCopy: () => builderPluginAdapterCopy
|
22
22
|
});
|
23
|
-
module.exports = __toCommonJS(
|
23
|
+
module.exports = __toCommonJS(adapterCopy_exports);
|
24
24
|
var import_createCopyPattern = require("./createCopyPattern");
|
25
|
-
const
|
26
|
-
name: "builder-plugin-adapter-
|
25
|
+
const builderPluginAdapterCopy = (options) => ({
|
26
|
+
name: "builder-plugin-adapter-copy",
|
27
27
|
setup(api) {
|
28
28
|
const { normalizedConfig: modernConfig, appContext } = options;
|
29
|
-
api.
|
29
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
30
30
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
31
31
|
const defaultCopyPattern = (0, import_createCopyPattern.createPublicPattern)(appContext, modernConfig, chain);
|
32
32
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
@@ -46,5 +46,5 @@ const builderPluginAdapterModern = (options) => ({
|
|
46
46
|
});
|
47
47
|
// Annotate the CommonJS export names for ESM import in node:
|
48
48
|
0 && (module.exports = {
|
49
|
-
|
49
|
+
builderPluginAdapterCopy
|
50
50
|
});
|
@@ -21,7 +21,7 @@ __export(createBuilderProviderConfig_exports, {
|
|
21
21
|
createBuilderProviderConfig: () => createBuilderProviderConfig
|
22
22
|
});
|
23
23
|
module.exports = __toCommonJS(createBuilderProviderConfig_exports);
|
24
|
-
var import_createCopyPattern = require("
|
24
|
+
var import_createCopyPattern = require("./createCopyPattern");
|
25
25
|
function modifyOutputConfig(config, appContext) {
|
26
26
|
const defaultCopyPattern = (0, import_createCopyPattern.createUploadPattern)(appContext, config);
|
27
27
|
const { copy } = config.output;
|
@@ -23,7 +23,8 @@ __export(getBuilderEnvironments_exports, {
|
|
23
23
|
module.exports = __toCommonJS(getBuilderEnvironments_exports);
|
24
24
|
var import_uni_builder = require("@modern-js/uni-builder");
|
25
25
|
var import_utils = require("@modern-js/utils");
|
26
|
-
function getBuilderEnvironments(normalizedConfig, appContext) {
|
26
|
+
function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
|
27
|
+
var _tempBuilderConfig_output;
|
27
28
|
const entries = {};
|
28
29
|
const { entrypoints = [], checkedEntries } = appContext;
|
29
30
|
for (const { entryName, internalEntry, entry } of entrypoints) {
|
@@ -54,6 +55,10 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
54
55
|
}
|
55
56
|
}
|
56
57
|
};
|
58
|
+
if ((_tempBuilderConfig_output = tempBuilderConfig.output) === null || _tempBuilderConfig_output === void 0 ? void 0 : _tempBuilderConfig_output.copy) {
|
59
|
+
environments.web.output.copy = tempBuilderConfig.output.copy;
|
60
|
+
delete tempBuilderConfig.output.copy;
|
61
|
+
}
|
57
62
|
const useNodeTarget = (0, import_utils.isProd)() ? (0, import_utils.isUseSSRBundle)(normalizedConfig) : (0, import_utils.isSSR)(normalizedConfig);
|
58
63
|
if (useNodeTarget) {
|
59
64
|
environments.node = {
|
@@ -76,7 +81,10 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
76
81
|
}
|
77
82
|
};
|
78
83
|
}
|
79
|
-
return
|
84
|
+
return {
|
85
|
+
environments,
|
86
|
+
builderConfig: tempBuilderConfig
|
87
|
+
};
|
80
88
|
}
|
81
89
|
// Annotate the CommonJS export names for ESM import in node:
|
82
90
|
0 && (module.exports = {
|
@@ -33,12 +33,13 @@ __export(generator_exports, {
|
|
33
33
|
module.exports = __toCommonJS(generator_exports);
|
34
34
|
var import_uni_builder = require("@modern-js/uni-builder");
|
35
35
|
var import_core = require("@rsbuild/core");
|
36
|
+
var import_adapterCopy = require("./adapterCopy");
|
36
37
|
var import_createBuilderProviderConfig = require("./createBuilderProviderConfig");
|
37
38
|
var import_getBuilderEnvironments = require("./getBuilderEnvironments");
|
38
39
|
async function generateBuilder(options, bundlerType) {
|
39
40
|
const { normalizedConfig, appContext } = options;
|
40
|
-
const
|
41
|
-
const environments = (0, import_getBuilderEnvironments.getBuilderEnvironments)(normalizedConfig, appContext);
|
41
|
+
const tempBuilderConfig = (0, import_createBuilderProviderConfig.createBuilderProviderConfig)(normalizedConfig, appContext);
|
42
|
+
const { environments, builderConfig } = (0, import_getBuilderEnvironments.getBuilderEnvironments)(normalizedConfig, appContext, tempBuilderConfig);
|
42
43
|
builderConfig.environments = builderConfig.environments ? (0, import_core.mergeRsbuildConfig)(environments, builderConfig.environments) : environments;
|
43
44
|
const builder = await (0, import_uni_builder.createUniBuilder)({
|
44
45
|
cwd: appContext.appDirectory,
|
@@ -56,6 +57,11 @@ async function applyBuilderPlugins(builder, options) {
|
|
56
57
|
builderPluginAdapterSSR(options),
|
57
58
|
builderPluginAdapterHtml(options)
|
58
59
|
]);
|
60
|
+
builder.addPlugins([
|
61
|
+
(0, import_adapterCopy.builderPluginAdapterCopy)(options)
|
62
|
+
], {
|
63
|
+
environment: "web"
|
64
|
+
});
|
59
65
|
const { normalizedConfig } = options;
|
60
66
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
61
67
|
const { pluginNodePolyfill } = await import("@rsbuild/plugin-node-polyfill");
|
package/dist/cjs/index.js
CHANGED
@@ -37,6 +37,7 @@ __export(src_exports, {
|
|
37
37
|
module.exports = __toCommonJS(src_exports);
|
38
38
|
var import_path = __toESM(require("path"));
|
39
39
|
var import_language_detector = require("@modern-js/plugin-i18n/language-detector");
|
40
|
+
var import_uni_builder = require("@modern-js/uni-builder");
|
40
41
|
var import_utils = require("@modern-js/utils");
|
41
42
|
var import_hooks = require("./hooks");
|
42
43
|
var import_locale = require("./locale");
|
@@ -139,7 +140,16 @@ const appTools = (options = {
|
|
139
140
|
async watchFiles() {
|
140
141
|
const appContext2 = api.useAppContext();
|
141
142
|
const config = api.useResolvedConfigContext();
|
142
|
-
|
143
|
+
const files = await (0, import_generateWatchFiles.generateWatchFiles)(appContext2, config.source.configDir);
|
144
|
+
const watchFiles = (0, import_uni_builder.castArray)(config.dev.watchFiles);
|
145
|
+
watchFiles.forEach(({ type, paths }) => {
|
146
|
+
if (type === "reload-server") {
|
147
|
+
files.push(...Array.isArray(paths) ? paths : [
|
148
|
+
paths
|
149
|
+
]);
|
150
|
+
}
|
151
|
+
});
|
152
|
+
return files;
|
143
153
|
},
|
144
154
|
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
145
155
|
async fileChange(e) {
|
@@ -83,7 +83,7 @@ const registerCompiler = async (appDir, distDir, alias) => {
|
|
83
83
|
const { MODERN_NODE_LOADER } = process.env;
|
84
84
|
if (MODERN_NODE_LOADER !== "esbuild") {
|
85
85
|
try {
|
86
|
-
const tsNode = await
|
86
|
+
const tsNode = await (0, import_utils.loadFromProject)("ts-node", appDir);
|
87
87
|
const tsNodeOptions = tsConfig["ts-node"];
|
88
88
|
if (isTsProject) {
|
89
89
|
tsNode.register({
|
@@ -100,6 +100,7 @@ const registerCompiler = async (appDir, distDir, alias) => {
|
|
100
100
|
});
|
101
101
|
}
|
102
102
|
} catch (error) {
|
103
|
+
import_utils.logger.error(error);
|
103
104
|
await registerEsbuild({
|
104
105
|
isTsProject,
|
105
106
|
tsConfig,
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import { generateBuilder } from "../generator";
|
4
|
-
import { builderPluginAdpaterCopy } from "./adapterCopy";
|
5
4
|
function createRspackBuilderForModern(options) {
|
6
5
|
return _createRspackBuilderForModern.apply(this, arguments);
|
7
6
|
}
|
@@ -17,9 +16,6 @@ function _createRspackBuilderForModern() {
|
|
17
16
|
];
|
18
17
|
case 1:
|
19
18
|
builder = _state.sent();
|
20
|
-
builder.addPlugins([
|
21
|
-
builderPluginAdpaterCopy(options)
|
22
|
-
]);
|
23
19
|
return [
|
24
20
|
2,
|
25
21
|
builder
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import { generateBuilder } from "../generator";
|
4
|
-
import { builderPluginAdapterModern } from "./adapterModern";
|
5
4
|
function createWebpackBuilderForModern(options) {
|
6
5
|
return _createWebpackBuilderForModern.apply(this, arguments);
|
7
6
|
}
|
@@ -35,9 +34,6 @@ function _createWebpackBuilderForModern() {
|
|
35
34
|
]);
|
36
35
|
_state.label = 3;
|
37
36
|
case 3:
|
38
|
-
builder.addPlugins([
|
39
|
-
builderPluginAdapterModern(options)
|
40
|
-
]);
|
41
37
|
return [
|
42
38
|
2,
|
43
39
|
builder
|
@@ -1,11 +1,11 @@
|
|
1
1
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
2
2
|
import { createPublicPattern } from "./createCopyPattern";
|
3
|
-
var
|
3
|
+
var builderPluginAdapterCopy = function(options) {
|
4
4
|
return {
|
5
|
-
name: "builder-plugin-adapter-
|
5
|
+
name: "builder-plugin-adapter-copy",
|
6
6
|
setup: function setup(api) {
|
7
7
|
var modernConfig = options.normalizedConfig, appContext = options.appContext;
|
8
|
-
api.
|
8
|
+
api.modifyBundlerChain(function(chain, param) {
|
9
9
|
var CHAIN_ID = param.CHAIN_ID;
|
10
10
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
11
11
|
var defaultCopyPattern = createPublicPattern(appContext, modernConfig, chain);
|
@@ -25,5 +25,5 @@ var builderPluginAdapterModern = function(options) {
|
|
25
25
|
};
|
26
26
|
};
|
27
27
|
export {
|
28
|
-
|
28
|
+
builderPluginAdapterCopy
|
29
29
|
};
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
2
2
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
4
|
-
import { createUploadPattern } from "
|
4
|
+
import { createUploadPattern } from "./createCopyPattern";
|
5
5
|
function modifyOutputConfig(config, appContext) {
|
6
6
|
var defaultCopyPattern = createUploadPattern(appContext, config);
|
7
7
|
var copy = config.output.copy;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
|
2
2
|
import { isProd, isSSR, isServiceWorker, isUseSSRBundle } from "@modern-js/utils";
|
3
|
-
function getBuilderEnvironments(normalizedConfig, appContext) {
|
3
|
+
function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
|
4
|
+
var _tempBuilderConfig_output;
|
4
5
|
var entries = {};
|
5
6
|
var _appContext_entrypoints = appContext.entrypoints, entrypoints = _appContext_entrypoints === void 0 ? [] : _appContext_entrypoints, checkedEntries = appContext.checkedEntries;
|
6
7
|
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
@@ -52,6 +53,10 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
52
53
|
}
|
53
54
|
}
|
54
55
|
};
|
56
|
+
if ((_tempBuilderConfig_output = tempBuilderConfig.output) === null || _tempBuilderConfig_output === void 0 ? void 0 : _tempBuilderConfig_output.copy) {
|
57
|
+
environments.web.output.copy = tempBuilderConfig.output.copy;
|
58
|
+
delete tempBuilderConfig.output.copy;
|
59
|
+
}
|
55
60
|
var useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
|
56
61
|
if (useNodeTarget) {
|
57
62
|
environments.node = {
|
@@ -74,7 +79,10 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
74
79
|
}
|
75
80
|
};
|
76
81
|
}
|
77
|
-
return
|
82
|
+
return {
|
83
|
+
environments,
|
84
|
+
builderConfig: tempBuilderConfig
|
85
|
+
};
|
78
86
|
}
|
79
87
|
export {
|
80
88
|
getBuilderEnvironments
|
@@ -2,6 +2,7 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
|
2
2
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
3
|
import { createUniBuilder } from "@modern-js/uni-builder";
|
4
4
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
5
|
+
import { builderPluginAdapterCopy } from "./adapterCopy";
|
5
6
|
import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
|
6
7
|
import { getBuilderEnvironments } from "./getBuilderEnvironments";
|
7
8
|
function generateBuilder(options, bundlerType) {
|
@@ -9,13 +10,13 @@ function generateBuilder(options, bundlerType) {
|
|
9
10
|
}
|
10
11
|
function _generateBuilder() {
|
11
12
|
_generateBuilder = _async_to_generator(function(options, bundlerType) {
|
12
|
-
var normalizedConfig, appContext,
|
13
|
+
var normalizedConfig, appContext, tempBuilderConfig, _getBuilderEnvironments, environments, builderConfig, builder;
|
13
14
|
return _ts_generator(this, function(_state) {
|
14
15
|
switch (_state.label) {
|
15
16
|
case 0:
|
16
17
|
normalizedConfig = options.normalizedConfig, appContext = options.appContext;
|
17
|
-
|
18
|
-
|
18
|
+
tempBuilderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
|
19
|
+
_getBuilderEnvironments = getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig), environments = _getBuilderEnvironments.environments, builderConfig = _getBuilderEnvironments.builderConfig;
|
19
20
|
builderConfig.environments = builderConfig.environments ? mergeRsbuildConfig(environments, builderConfig.environments) : environments;
|
20
21
|
return [
|
21
22
|
4,
|
@@ -63,6 +64,11 @@ function _applyBuilderPlugins() {
|
|
63
64
|
builderPluginAdapterSSR(options),
|
64
65
|
builderPluginAdapterHtml(options)
|
65
66
|
]);
|
67
|
+
builder.addPlugins([
|
68
|
+
builderPluginAdapterCopy(options)
|
69
|
+
], {
|
70
|
+
environment: "web"
|
71
|
+
});
|
66
72
|
normalizedConfig = options.normalizedConfig;
|
67
73
|
if (!!normalizedConfig.output.disableNodePolyfill)
|
68
74
|
return [
|
package/dist/esm/index.js
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
2
|
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
3
|
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
4
5
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
6
|
import path from "path";
|
6
7
|
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
8
|
+
import { castArray } from "@modern-js/uni-builder";
|
7
9
|
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
8
10
|
import { hooks } from "./hooks";
|
9
11
|
import { i18n } from "./locale";
|
@@ -159,7 +161,7 @@ var appTools = function() {
|
|
159
161
|
},
|
160
162
|
watchFiles: function watchFiles() {
|
161
163
|
return _async_to_generator(function() {
|
162
|
-
var appContext2, config;
|
164
|
+
var appContext2, config, files, watchFiles2;
|
163
165
|
return _ts_generator(this, function(_state) {
|
164
166
|
switch (_state.label) {
|
165
167
|
case 0:
|
@@ -170,9 +172,20 @@ var appTools = function() {
|
|
170
172
|
generateWatchFiles(appContext2, config.source.configDir)
|
171
173
|
];
|
172
174
|
case 1:
|
175
|
+
files = _state.sent();
|
176
|
+
watchFiles2 = castArray(config.dev.watchFiles);
|
177
|
+
watchFiles2.forEach(function(param) {
|
178
|
+
var type = param.type, paths = param.paths;
|
179
|
+
if (type === "reload-server") {
|
180
|
+
var _files;
|
181
|
+
(_files = files).push.apply(_files, _to_consumable_array(Array.isArray(paths) ? paths : [
|
182
|
+
paths
|
183
|
+
]));
|
184
|
+
}
|
185
|
+
});
|
173
186
|
return [
|
174
187
|
2,
|
175
|
-
|
188
|
+
files
|
176
189
|
];
|
177
190
|
}
|
178
191
|
});
|
@@ -5,7 +5,7 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
5
5
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
6
6
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
7
7
|
import path from "node:path";
|
8
|
-
import { fs, getAliasConfig, readTsConfigByFile } from "@modern-js/utils";
|
8
|
+
import { fs, getAliasConfig, loadFromProject, logger, readTsConfigByFile } from "@modern-js/utils";
|
9
9
|
var registerEsbuild = function() {
|
10
10
|
var _ref = _async_to_generator(function(param) {
|
11
11
|
var isTsProject, tsConfig, distDir, esbuildRegister;
|
@@ -97,7 +97,7 @@ var registerCompiler = function() {
|
|
97
97
|
]);
|
98
98
|
return [
|
99
99
|
4,
|
100
|
-
|
100
|
+
loadFromProject("ts-node", appDir)
|
101
101
|
];
|
102
102
|
case 3:
|
103
103
|
tsNode = _state.sent();
|
@@ -121,6 +121,7 @@ var registerCompiler = function() {
|
|
121
121
|
];
|
122
122
|
case 4:
|
123
123
|
error = _state.sent();
|
124
|
+
logger.error(error);
|
124
125
|
return [
|
125
126
|
4,
|
126
127
|
registerEsbuild({
|
@@ -1,10 +1,6 @@
|
|
1
1
|
import { generateBuilder } from "../generator";
|
2
|
-
import { builderPluginAdpaterCopy } from "./adapterCopy";
|
3
2
|
async function createRspackBuilderForModern(options) {
|
4
3
|
const builder = await generateBuilder(options, "rspack");
|
5
|
-
builder.addPlugins([
|
6
|
-
builderPluginAdpaterCopy(options)
|
7
|
-
]);
|
8
4
|
return builder;
|
9
5
|
}
|
10
6
|
export {
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { generateBuilder } from "../generator";
|
2
|
-
import { builderPluginAdapterModern } from "./adapterModern";
|
3
2
|
async function createWebpackBuilderForModern(options) {
|
4
3
|
const builder = await generateBuilder(options, "webpack");
|
5
4
|
const { normalizedConfig } = options;
|
@@ -10,9 +9,6 @@ async function createWebpackBuilderForModern(options) {
|
|
10
9
|
pluginEsbuild(esbuildOptions)
|
11
10
|
]);
|
12
11
|
}
|
13
|
-
builder.addPlugins([
|
14
|
-
builderPluginAdapterModern(options)
|
15
|
-
]);
|
16
12
|
return builder;
|
17
13
|
}
|
18
14
|
export {
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import { createPublicPattern } from "./createCopyPattern";
|
2
|
-
const
|
3
|
-
name: "builder-plugin-adapter-
|
2
|
+
const builderPluginAdapterCopy = (options) => ({
|
3
|
+
name: "builder-plugin-adapter-copy",
|
4
4
|
setup(api) {
|
5
5
|
const { normalizedConfig: modernConfig, appContext } = options;
|
6
|
-
api.
|
6
|
+
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
7
7
|
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
8
8
|
const defaultCopyPattern = createPublicPattern(appContext, modernConfig, chain);
|
9
9
|
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
@@ -22,5 +22,5 @@ const builderPluginAdapterModern = (options) => ({
|
|
22
22
|
}
|
23
23
|
});
|
24
24
|
export {
|
25
|
-
|
25
|
+
builderPluginAdapterCopy
|
26
26
|
};
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { createUploadPattern } from "
|
1
|
+
import { createUploadPattern } from "./createCopyPattern";
|
2
2
|
function modifyOutputConfig(config, appContext) {
|
3
3
|
const defaultCopyPattern = createUploadPattern(appContext, config);
|
4
4
|
const { copy } = config.output;
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import { SERVICE_WORKER_ENVIRONMENT_NAME } from "@modern-js/uni-builder";
|
2
2
|
import { isProd, isSSR, isServiceWorker, isUseSSRBundle } from "@modern-js/utils";
|
3
|
-
function getBuilderEnvironments(normalizedConfig, appContext) {
|
3
|
+
function getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig) {
|
4
|
+
var _tempBuilderConfig_output;
|
4
5
|
const entries = {};
|
5
6
|
const { entrypoints = [], checkedEntries } = appContext;
|
6
7
|
for (const { entryName, internalEntry, entry } of entrypoints) {
|
@@ -31,6 +32,10 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
31
32
|
}
|
32
33
|
}
|
33
34
|
};
|
35
|
+
if ((_tempBuilderConfig_output = tempBuilderConfig.output) === null || _tempBuilderConfig_output === void 0 ? void 0 : _tempBuilderConfig_output.copy) {
|
36
|
+
environments.web.output.copy = tempBuilderConfig.output.copy;
|
37
|
+
delete tempBuilderConfig.output.copy;
|
38
|
+
}
|
34
39
|
const useNodeTarget = isProd() ? isUseSSRBundle(normalizedConfig) : isSSR(normalizedConfig);
|
35
40
|
if (useNodeTarget) {
|
36
41
|
environments.node = {
|
@@ -53,7 +58,10 @@ function getBuilderEnvironments(normalizedConfig, appContext) {
|
|
53
58
|
}
|
54
59
|
};
|
55
60
|
}
|
56
|
-
return
|
61
|
+
return {
|
62
|
+
environments,
|
63
|
+
builderConfig: tempBuilderConfig
|
64
|
+
};
|
57
65
|
}
|
58
66
|
export {
|
59
67
|
getBuilderEnvironments
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { createUniBuilder } from "@modern-js/uni-builder";
|
2
2
|
import { mergeRsbuildConfig } from "@rsbuild/core";
|
3
|
+
import { builderPluginAdapterCopy } from "./adapterCopy";
|
3
4
|
import { createBuilderProviderConfig } from "./createBuilderProviderConfig";
|
4
5
|
import { getBuilderEnvironments } from "./getBuilderEnvironments";
|
5
6
|
async function generateBuilder(options, bundlerType) {
|
6
7
|
const { normalizedConfig, appContext } = options;
|
7
|
-
const
|
8
|
-
const environments = getBuilderEnvironments(normalizedConfig, appContext);
|
8
|
+
const tempBuilderConfig = createBuilderProviderConfig(normalizedConfig, appContext);
|
9
|
+
const { environments, builderConfig } = getBuilderEnvironments(normalizedConfig, appContext, tempBuilderConfig);
|
9
10
|
builderConfig.environments = builderConfig.environments ? mergeRsbuildConfig(environments, builderConfig.environments) : environments;
|
10
11
|
const builder = await createUniBuilder({
|
11
12
|
cwd: appContext.appDirectory,
|
@@ -23,6 +24,11 @@ async function applyBuilderPlugins(builder, options) {
|
|
23
24
|
builderPluginAdapterSSR(options),
|
24
25
|
builderPluginAdapterHtml(options)
|
25
26
|
]);
|
27
|
+
builder.addPlugins([
|
28
|
+
builderPluginAdapterCopy(options)
|
29
|
+
], {
|
30
|
+
environment: "web"
|
31
|
+
});
|
26
32
|
const { normalizedConfig } = options;
|
27
33
|
if (!normalizedConfig.output.disableNodePolyfill) {
|
28
34
|
const { pluginNodePolyfill } = await import("@rsbuild/plugin-node-polyfill");
|
package/dist/esm-node/index.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import path from "path";
|
2
2
|
import { getLocaleLanguage } from "@modern-js/plugin-i18n/language-detector";
|
3
|
+
import { castArray } from "@modern-js/uni-builder";
|
3
4
|
import { cleanRequireCache, deprecatedCommands, emptyDir, getArgv, getCommand } from "@modern-js/utils";
|
4
5
|
import { hooks } from "./hooks";
|
5
6
|
import { i18n } from "./locale";
|
@@ -102,7 +103,16 @@ const appTools = (options = {
|
|
102
103
|
async watchFiles() {
|
103
104
|
const appContext2 = api.useAppContext();
|
104
105
|
const config = api.useResolvedConfigContext();
|
105
|
-
|
106
|
+
const files = await generateWatchFiles(appContext2, config.source.configDir);
|
107
|
+
const watchFiles = castArray(config.dev.watchFiles);
|
108
|
+
watchFiles.forEach(({ type, paths }) => {
|
109
|
+
if (type === "reload-server") {
|
110
|
+
files.push(...Array.isArray(paths) ? paths : [
|
111
|
+
paths
|
112
|
+
]);
|
113
|
+
}
|
114
|
+
});
|
115
|
+
return files;
|
106
116
|
},
|
107
117
|
// 这里会被 core/initWatcher 监听的文件变动触发,如果是 src 目录下的文件变动,则不做 restart
|
108
118
|
async fileChange(e) {
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import path from "node:path";
|
2
|
-
import { fs, getAliasConfig, readTsConfigByFile } from "@modern-js/utils";
|
2
|
+
import { fs, getAliasConfig, loadFromProject, logger, readTsConfigByFile } from "@modern-js/utils";
|
3
3
|
const registerEsbuild = async ({ isTsProject, tsConfig, distDir }) => {
|
4
4
|
const esbuildRegister = await import("esbuild-register/dist/node");
|
5
5
|
esbuildRegister.register({
|
@@ -50,7 +50,7 @@ const registerCompiler = async (appDir, distDir, alias) => {
|
|
50
50
|
const { MODERN_NODE_LOADER } = process.env;
|
51
51
|
if (MODERN_NODE_LOADER !== "esbuild") {
|
52
52
|
try {
|
53
|
-
const tsNode = await
|
53
|
+
const tsNode = await loadFromProject("ts-node", appDir);
|
54
54
|
const tsNodeOptions = tsConfig["ts-node"];
|
55
55
|
if (isTsProject) {
|
56
56
|
tsNode.register({
|
@@ -67,6 +67,7 @@ const registerCompiler = async (appDir, distDir, alias) => {
|
|
67
67
|
});
|
68
68
|
}
|
69
69
|
} catch (error) {
|
70
|
+
logger.error(error);
|
70
71
|
await registerEsbuild({
|
71
72
|
isTsProject,
|
72
73
|
tsConfig,
|
@@ -1,5 +1,8 @@
|
|
1
1
|
import type { IAppContext } from '@modern-js/core';
|
2
|
-
import type { AppNormalizedConfig } from '../../types';
|
3
|
-
export declare function getBuilderEnvironments(normalizedConfig: AppNormalizedConfig<'shared'>, appContext: IAppContext): {
|
4
|
-
|
2
|
+
import type { AppNormalizedConfig, Bundler } from '../../types';
|
3
|
+
export declare function getBuilderEnvironments<B extends Bundler>(normalizedConfig: AppNormalizedConfig<'shared'>, appContext: IAppContext, tempBuilderConfig: Omit<AppNormalizedConfig<B>, 'plugins'>): {
|
4
|
+
environments: {
|
5
|
+
[name: string]: import("@rsbuild/core").EnvironmentConfig;
|
6
|
+
};
|
7
|
+
builderConfig: Omit<AppNormalizedConfig<B_1>, "plugins">;
|
5
8
|
};
|
package/package.json
CHANGED
@@ -15,7 +15,7 @@
|
|
15
15
|
"modern",
|
16
16
|
"modern.js"
|
17
17
|
],
|
18
|
-
"version": "2.60.
|
18
|
+
"version": "2.60.3",
|
19
19
|
"jsnext:source": "./src/index.ts",
|
20
20
|
"types": "./dist/types/index.d.ts",
|
21
21
|
"main": "./dist/cjs/index.js",
|
@@ -77,8 +77,8 @@
|
|
77
77
|
"@babel/parser": "^7.22.15",
|
78
78
|
"@babel/traverse": "^7.23.2",
|
79
79
|
"@babel/types": "^7.24.7",
|
80
|
-
"@rsbuild/core": "1.0.
|
81
|
-
"@rsbuild/plugin-node-polyfill": "1.0.4",
|
80
|
+
"@rsbuild/core": "~1.0.11",
|
81
|
+
"@rsbuild/plugin-node-polyfill": "~1.0.4",
|
82
82
|
"@swc/helpers": "0.5.13",
|
83
83
|
"@vercel/nft": "^0.26.4",
|
84
84
|
"es-module-lexer": "^1.1.0",
|
@@ -88,22 +88,22 @@
|
|
88
88
|
"mlly": "^1.6.1",
|
89
89
|
"pkg-types": "^1.1.0",
|
90
90
|
"std-env": "^3.7.0",
|
91
|
-
"@modern-js/
|
92
|
-
"@modern-js/
|
93
|
-
"@modern-js/plugin": "2.60.
|
94
|
-
"@modern-js/plugin-
|
95
|
-
"@modern-js/plugin-
|
96
|
-
"@modern-js/
|
97
|
-
"@modern-js/
|
98
|
-
"@modern-js/
|
99
|
-
"@modern-js/server": "2.60.
|
100
|
-
"@modern-js/
|
101
|
-
"@modern-js/types": "2.60.
|
102
|
-
"@modern-js/
|
103
|
-
"@modern-js/
|
91
|
+
"@modern-js/node-bundle-require": "2.60.3",
|
92
|
+
"@modern-js/plugin": "2.60.3",
|
93
|
+
"@modern-js/plugin-i18n": "2.60.3",
|
94
|
+
"@modern-js/plugin-data-loader": "2.60.3",
|
95
|
+
"@modern-js/rsbuild-plugin-esbuild": "2.60.3",
|
96
|
+
"@modern-js/prod-server": "2.60.3",
|
97
|
+
"@modern-js/server": "2.60.3",
|
98
|
+
"@modern-js/core": "2.60.3",
|
99
|
+
"@modern-js/server-core": "2.60.3",
|
100
|
+
"@modern-js/server-utils": "2.60.3",
|
101
|
+
"@modern-js/types": "2.60.3",
|
102
|
+
"@modern-js/uni-builder": "2.60.3",
|
103
|
+
"@modern-js/utils": "2.60.3"
|
104
104
|
},
|
105
105
|
"devDependencies": {
|
106
|
-
"@rsbuild/plugin-webpack-swc": "1.0.3",
|
106
|
+
"@rsbuild/plugin-webpack-swc": "~1.0.3",
|
107
107
|
"@types/babel__traverse": "7.20.6",
|
108
108
|
"@types/jest": "^29",
|
109
109
|
"@types/node": "^16",
|
@@ -111,9 +111,9 @@
|
|
111
111
|
"ts-node": "^10.9.1",
|
112
112
|
"tsconfig-paths": "^4.2.0",
|
113
113
|
"typescript": "^5",
|
114
|
-
"webpack": "^5.
|
115
|
-
"@scripts/
|
116
|
-
"@scripts/
|
114
|
+
"webpack": "^5.95.0",
|
115
|
+
"@scripts/jest-config": "2.60.3",
|
116
|
+
"@scripts/build": "2.60.3"
|
117
117
|
},
|
118
118
|
"peerDependencies": {
|
119
119
|
"ts-node": "^10.7.0",
|
@@ -1,101 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __create = Object.create;
|
3
|
-
var __defProp = Object.defineProperty;
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
-
var __export = (target, all) => {
|
9
|
-
for (var name in all)
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
-
};
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
-
for (let key of __getOwnPropNames(from))
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
-
}
|
18
|
-
return to;
|
19
|
-
};
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
-
mod
|
27
|
-
));
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
-
var adapterCopy_exports = {};
|
30
|
-
__export(adapterCopy_exports, {
|
31
|
-
builderPluginAdpaterCopy: () => builderPluginAdpaterCopy
|
32
|
-
});
|
33
|
-
module.exports = __toCommonJS(adapterCopy_exports);
|
34
|
-
var import_path = __toESM(require("path"));
|
35
|
-
var import_utils = require("@modern-js/utils");
|
36
|
-
var import_fs_extra = __toESM(require("@modern-js/utils/fs-extra"));
|
37
|
-
var import_shared = require("../shared");
|
38
|
-
const builderPluginAdpaterCopy = (options) => ({
|
39
|
-
name: "builder-plugin-adapter-rspack-copy",
|
40
|
-
setup(api) {
|
41
|
-
let publicPath;
|
42
|
-
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
43
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
44
|
-
var _args_;
|
45
|
-
return [
|
46
|
-
{
|
47
|
-
patterns: [
|
48
|
-
...((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || [],
|
49
|
-
...createConfigBuiltinCopy(options)
|
50
|
-
]
|
51
|
-
}
|
52
|
-
];
|
53
|
-
});
|
54
|
-
});
|
55
|
-
api.modifyRspackConfig((config) => {
|
56
|
-
var _config_output;
|
57
|
-
publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
|
58
|
-
});
|
59
|
-
api.onDevCompileDone(async () => {
|
60
|
-
await transformHtmlFiles();
|
61
|
-
});
|
62
|
-
api.onAfterBuild(async () => {
|
63
|
-
await transformHtmlFiles();
|
64
|
-
});
|
65
|
-
async function transformHtmlFiles() {
|
66
|
-
var _normalizedConfig_output_distPath;
|
67
|
-
const { normalizedConfig } = options;
|
68
|
-
const publicDir = import_path.default.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
|
69
|
-
if (!import_fs_extra.default.existsSync(publicDir) || !import_fs_extra.default.statSync(publicDir).isDirectory()) {
|
70
|
-
return;
|
71
|
-
}
|
72
|
-
const HTML_REGEXP = /\.html?$/;
|
73
|
-
const filepaths = (await import_fs_extra.default.readdir(publicDir)).map((file) => import_path.default.resolve(publicDir, file));
|
74
|
-
await Promise.all(filepaths.filter((file) => HTML_REGEXP.test(file)).map(async (file) => {
|
75
|
-
const content = await import_fs_extra.default.readFile(file, "utf-8");
|
76
|
-
if (publicPath && typeof publicPath === "string") {
|
77
|
-
await import_fs_extra.default.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, (0, import_utils.removeTailSlash)(publicPath)));
|
78
|
-
} else {
|
79
|
-
import_utils.logger.warn(`Expect get a string from \`publicPath\`, but receive \`${typeof publicPath}\`.`);
|
80
|
-
await import_fs_extra.default.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, (0, import_utils.removeTailSlash)("/")));
|
81
|
-
}
|
82
|
-
}));
|
83
|
-
}
|
84
|
-
}
|
85
|
-
});
|
86
|
-
function createConfigBuiltinCopy(options) {
|
87
|
-
const { normalizedConfig, appContext } = options;
|
88
|
-
const { publicDir } = (0, import_shared.createCopyInfo)(appContext, normalizedConfig);
|
89
|
-
return [
|
90
|
-
{
|
91
|
-
from: "**/*",
|
92
|
-
to: "public",
|
93
|
-
context: publicDir,
|
94
|
-
noErrorOnMissing: true
|
95
|
-
}
|
96
|
-
];
|
97
|
-
}
|
98
|
-
// Annotate the CommonJS export names for ESM import in node:
|
99
|
-
0 && (module.exports = {
|
100
|
-
builderPluginAdpaterCopy
|
101
|
-
});
|
@@ -1,166 +0,0 @@
|
|
1
|
-
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
-
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
3
|
-
import { _ as _type_of } from "@swc/helpers/_/_type_of";
|
4
|
-
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
-
import path from "path";
|
6
|
-
import { logger, removeTailSlash } from "@modern-js/utils";
|
7
|
-
import fs from "@modern-js/utils/fs-extra";
|
8
|
-
import { createCopyInfo } from "../shared";
|
9
|
-
var builderPluginAdpaterCopy = function(options) {
|
10
|
-
return {
|
11
|
-
name: "builder-plugin-adapter-rspack-copy",
|
12
|
-
setup: function setup(api) {
|
13
|
-
var publicPath;
|
14
|
-
api.modifyBundlerChain(function(chain, param) {
|
15
|
-
var CHAIN_ID = param.CHAIN_ID;
|
16
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap(function(args) {
|
17
|
-
var _args_;
|
18
|
-
return [
|
19
|
-
{
|
20
|
-
patterns: _to_consumable_array(((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || []).concat(_to_consumable_array(createConfigBuiltinCopy(options)))
|
21
|
-
}
|
22
|
-
];
|
23
|
-
});
|
24
|
-
});
|
25
|
-
api.modifyRspackConfig(function(config) {
|
26
|
-
var _config_output;
|
27
|
-
publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
|
28
|
-
});
|
29
|
-
api.onDevCompileDone(/* @__PURE__ */ _async_to_generator(function() {
|
30
|
-
return _ts_generator(this, function(_state) {
|
31
|
-
switch (_state.label) {
|
32
|
-
case 0:
|
33
|
-
return [
|
34
|
-
4,
|
35
|
-
transformHtmlFiles()
|
36
|
-
];
|
37
|
-
case 1:
|
38
|
-
_state.sent();
|
39
|
-
return [
|
40
|
-
2
|
41
|
-
];
|
42
|
-
}
|
43
|
-
});
|
44
|
-
}));
|
45
|
-
api.onAfterBuild(/* @__PURE__ */ _async_to_generator(function() {
|
46
|
-
return _ts_generator(this, function(_state) {
|
47
|
-
switch (_state.label) {
|
48
|
-
case 0:
|
49
|
-
return [
|
50
|
-
4,
|
51
|
-
transformHtmlFiles()
|
52
|
-
];
|
53
|
-
case 1:
|
54
|
-
_state.sent();
|
55
|
-
return [
|
56
|
-
2
|
57
|
-
];
|
58
|
-
}
|
59
|
-
});
|
60
|
-
}));
|
61
|
-
function transformHtmlFiles() {
|
62
|
-
return _transformHtmlFiles.apply(this, arguments);
|
63
|
-
}
|
64
|
-
function _transformHtmlFiles() {
|
65
|
-
_transformHtmlFiles = /** transform public/*.html manaully */
|
66
|
-
_async_to_generator(function() {
|
67
|
-
var _normalizedConfig_output_distPath, normalizedConfig, publicDir, HTML_REGEXP, filepaths;
|
68
|
-
return _ts_generator(this, function(_state) {
|
69
|
-
switch (_state.label) {
|
70
|
-
case 0:
|
71
|
-
normalizedConfig = options.normalizedConfig;
|
72
|
-
publicDir = path.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
|
73
|
-
if (!fs.existsSync(publicDir) || !fs.statSync(publicDir).isDirectory()) {
|
74
|
-
return [
|
75
|
-
2
|
76
|
-
];
|
77
|
-
}
|
78
|
-
HTML_REGEXP = /\.html?$/;
|
79
|
-
return [
|
80
|
-
4,
|
81
|
-
fs.readdir(publicDir)
|
82
|
-
];
|
83
|
-
case 1:
|
84
|
-
filepaths = _state.sent().map(function(file) {
|
85
|
-
return path.resolve(publicDir, file);
|
86
|
-
});
|
87
|
-
return [
|
88
|
-
4,
|
89
|
-
Promise.all(filepaths.filter(function(file) {
|
90
|
-
return HTML_REGEXP.test(file);
|
91
|
-
}).map(function() {
|
92
|
-
var _ref = _async_to_generator(function(file) {
|
93
|
-
var content;
|
94
|
-
return _ts_generator(this, function(_state2) {
|
95
|
-
switch (_state2.label) {
|
96
|
-
case 0:
|
97
|
-
return [
|
98
|
-
4,
|
99
|
-
fs.readFile(file, "utf-8")
|
100
|
-
];
|
101
|
-
case 1:
|
102
|
-
content = _state2.sent();
|
103
|
-
if (!(publicPath && typeof publicPath === "string"))
|
104
|
-
return [
|
105
|
-
3,
|
106
|
-
3
|
107
|
-
];
|
108
|
-
return [
|
109
|
-
4,
|
110
|
-
fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(publicPath)))
|
111
|
-
];
|
112
|
-
case 2:
|
113
|
-
_state2.sent();
|
114
|
-
return [
|
115
|
-
3,
|
116
|
-
5
|
117
|
-
];
|
118
|
-
case 3:
|
119
|
-
logger.warn("Expect get a string from `publicPath`, but receive `".concat(typeof publicPath === "undefined" ? "undefined" : _type_of(publicPath), "`."));
|
120
|
-
return [
|
121
|
-
4,
|
122
|
-
fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash("/")))
|
123
|
-
];
|
124
|
-
case 4:
|
125
|
-
_state2.sent();
|
126
|
-
_state2.label = 5;
|
127
|
-
case 5:
|
128
|
-
return [
|
129
|
-
2
|
130
|
-
];
|
131
|
-
}
|
132
|
-
});
|
133
|
-
});
|
134
|
-
return function(file) {
|
135
|
-
return _ref.apply(this, arguments);
|
136
|
-
};
|
137
|
-
}()))
|
138
|
-
];
|
139
|
-
case 2:
|
140
|
-
_state.sent();
|
141
|
-
return [
|
142
|
-
2
|
143
|
-
];
|
144
|
-
}
|
145
|
-
});
|
146
|
-
});
|
147
|
-
return _transformHtmlFiles.apply(this, arguments);
|
148
|
-
}
|
149
|
-
}
|
150
|
-
};
|
151
|
-
};
|
152
|
-
function createConfigBuiltinCopy(options) {
|
153
|
-
var normalizedConfig = options.normalizedConfig, appContext = options.appContext;
|
154
|
-
var publicDir = createCopyInfo(appContext, normalizedConfig).publicDir;
|
155
|
-
return [
|
156
|
-
{
|
157
|
-
from: "**/*",
|
158
|
-
to: "public",
|
159
|
-
context: publicDir,
|
160
|
-
noErrorOnMissing: true
|
161
|
-
}
|
162
|
-
];
|
163
|
-
}
|
164
|
-
export {
|
165
|
-
builderPluginAdpaterCopy
|
166
|
-
};
|
@@ -1,67 +0,0 @@
|
|
1
|
-
import path from "path";
|
2
|
-
import { logger, removeTailSlash } from "@modern-js/utils";
|
3
|
-
import fs from "@modern-js/utils/fs-extra";
|
4
|
-
import { createCopyInfo } from "../shared";
|
5
|
-
const builderPluginAdpaterCopy = (options) => ({
|
6
|
-
name: "builder-plugin-adapter-rspack-copy",
|
7
|
-
setup(api) {
|
8
|
-
let publicPath;
|
9
|
-
api.modifyBundlerChain((chain, { CHAIN_ID }) => {
|
10
|
-
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
11
|
-
var _args_;
|
12
|
-
return [
|
13
|
-
{
|
14
|
-
patterns: [
|
15
|
-
...((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || [],
|
16
|
-
...createConfigBuiltinCopy(options)
|
17
|
-
]
|
18
|
-
}
|
19
|
-
];
|
20
|
-
});
|
21
|
-
});
|
22
|
-
api.modifyRspackConfig((config) => {
|
23
|
-
var _config_output;
|
24
|
-
publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
|
25
|
-
});
|
26
|
-
api.onDevCompileDone(async () => {
|
27
|
-
await transformHtmlFiles();
|
28
|
-
});
|
29
|
-
api.onAfterBuild(async () => {
|
30
|
-
await transformHtmlFiles();
|
31
|
-
});
|
32
|
-
async function transformHtmlFiles() {
|
33
|
-
var _normalizedConfig_output_distPath;
|
34
|
-
const { normalizedConfig } = options;
|
35
|
-
const publicDir = path.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
|
36
|
-
if (!fs.existsSync(publicDir) || !fs.statSync(publicDir).isDirectory()) {
|
37
|
-
return;
|
38
|
-
}
|
39
|
-
const HTML_REGEXP = /\.html?$/;
|
40
|
-
const filepaths = (await fs.readdir(publicDir)).map((file) => path.resolve(publicDir, file));
|
41
|
-
await Promise.all(filepaths.filter((file) => HTML_REGEXP.test(file)).map(async (file) => {
|
42
|
-
const content = await fs.readFile(file, "utf-8");
|
43
|
-
if (publicPath && typeof publicPath === "string") {
|
44
|
-
await fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash(publicPath)));
|
45
|
-
} else {
|
46
|
-
logger.warn(`Expect get a string from \`publicPath\`, but receive \`${typeof publicPath}\`.`);
|
47
|
-
await fs.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, removeTailSlash("/")));
|
48
|
-
}
|
49
|
-
}));
|
50
|
-
}
|
51
|
-
}
|
52
|
-
});
|
53
|
-
function createConfigBuiltinCopy(options) {
|
54
|
-
const { normalizedConfig, appContext } = options;
|
55
|
-
const { publicDir } = createCopyInfo(appContext, normalizedConfig);
|
56
|
-
return [
|
57
|
-
{
|
58
|
-
from: "**/*",
|
59
|
-
to: "public",
|
60
|
-
context: publicDir,
|
61
|
-
noErrorOnMissing: true
|
62
|
-
}
|
63
|
-
];
|
64
|
-
}
|
65
|
-
export {
|
66
|
-
builderPluginAdpaterCopy
|
67
|
-
};
|
@@ -1,6 +0,0 @@
|
|
1
|
-
import type { RsbuildPlugin } from '@modern-js/uni-builder';
|
2
|
-
import type { BuilderOptions } from '../shared';
|
3
|
-
/**
|
4
|
-
* Provides default configuration consistent with modern.js v1
|
5
|
-
*/
|
6
|
-
export declare const builderPluginAdapterModern: (options: BuilderOptions<'webpack'>) => RsbuildPlugin;
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|