@modern-js/module-tools 2.35.1 → 2.36.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/dist/build.js +43 -16
- package/dist/builder/build.d.ts +1 -10
- package/dist/builder/build.js +96 -208
- package/dist/builder/clear.d.ts +1 -4
- package/dist/builder/clear.js +32 -28
- package/dist/builder/copy.js +75 -60
- package/dist/builder/dts/index.js +27 -19
- package/dist/builder/dts/rollup.d.ts +6 -14
- package/dist/builder/dts/rollup.js +60 -37
- package/dist/builder/dts/tsc.d.ts +3 -2
- package/dist/builder/dts/tsc.js +50 -37
- package/dist/builder/esbuild/adapter.d.ts +3 -0
- package/dist/builder/esbuild/adapter.js +275 -0
- package/dist/builder/esbuild/hook.d.ts +4 -0
- package/dist/builder/esbuild/hook.js +103 -0
- package/dist/builder/esbuild/index.d.ts +35 -0
- package/dist/builder/esbuild/index.js +268 -0
- package/dist/builder/esbuild/resolve.d.ts +17 -0
- package/dist/builder/esbuild/resolve.js +125 -0
- package/dist/builder/esbuild/sourcemap.d.ts +16 -0
- package/dist/builder/esbuild/sourcemap.js +86 -0
- package/dist/builder/esbuild/transform.d.ts +7 -0
- package/dist/builder/esbuild/transform.js +45 -0
- package/dist/builder/esbuild/watch.d.ts +2 -0
- package/dist/builder/esbuild/watch.js +115 -0
- package/dist/builder/esbuild/write-file.d.ts +2 -0
- package/dist/builder/esbuild/write-file.js +89 -0
- package/dist/builder/feature/asset.d.ts +19 -0
- package/dist/builder/feature/asset.js +149 -0
- package/dist/builder/feature/format-cjs.d.ts +5 -0
- package/dist/builder/feature/format-cjs.js +53 -0
- package/dist/builder/feature/index.d.ts +2 -0
- package/dist/builder/feature/index.js +74 -0
- package/dist/builder/feature/json.d.ts +5 -0
- package/dist/builder/feature/json.js +47 -0
- package/dist/builder/feature/redirect.d.ts +5 -0
- package/dist/builder/feature/redirect.js +217 -0
- package/dist/builder/feature/style/index.d.ts +5 -0
- package/dist/builder/feature/style/index.js +94 -0
- package/dist/builder/feature/style/lessAliasPlugin.d.ts +12 -0
- package/dist/builder/feature/style/lessAliasPlugin.js +70 -0
- package/dist/builder/feature/style/lessRender.d.ts +2 -0
- package/dist/builder/feature/style/lessRender.js +64 -0
- package/dist/builder/feature/style/postcssTransformer.d.ts +6 -0
- package/dist/builder/feature/style/postcssTransformer.js +95 -0
- package/dist/builder/feature/style/postcssUrlPlugin.d.ts +6 -0
- package/dist/builder/feature/style/postcssUrlPlugin.js +58 -0
- package/dist/builder/feature/style/sassRender.d.ts +2 -0
- package/dist/builder/feature/style/sassRender.js +85 -0
- package/dist/builder/feature/style/transformStyle.d.ts +13 -0
- package/dist/builder/feature/style/transformStyle.js +101 -0
- package/dist/builder/feature/style/utils.d.ts +18 -0
- package/dist/builder/feature/style/utils.js +124 -0
- package/dist/builder/feature/swc.d.ts +9 -0
- package/dist/builder/feature/swc.js +170 -0
- package/dist/builder/feature/terser.d.ts +5 -0
- package/dist/builder/feature/terser.js +83 -0
- package/dist/builder/index.d.ts +1 -0
- package/dist/builder/index.js +59 -28
- package/dist/builder/platform.js +38 -23
- package/dist/cli.js +58 -29
- package/dist/command.js +62 -38
- package/dist/config/defineConfig.js +25 -17
- package/dist/config/legacySchema.js +35 -32
- package/dist/config/merge.d.ts +1 -0
- package/dist/config/merge.js +69 -36
- package/dist/config/normalize.d.ts +1 -0
- package/dist/config/normalize.js +63 -46
- package/dist/config/schema.d.ts +48 -0
- package/dist/config/schema.js +53 -34
- package/dist/config/transformLegacyConfig.js +67 -61
- package/dist/config/valid.d.ts +2 -2
- package/dist/config/valid.js +44 -21
- package/dist/constants/build.d.ts +5 -1
- package/dist/constants/build.js +88 -46
- package/dist/constants/color.js +27 -20
- package/dist/constants/dts.js +27 -20
- package/dist/constants/file.d.ts +2 -2
- package/dist/constants/file.js +48 -25
- package/dist/constants/legacy-preset.js +45 -32
- package/dist/constants/loader.d.ts +2 -0
- package/dist/constants/loader.js +53 -0
- package/dist/constants/log.d.ts +0 -8
- package/dist/constants/log.js +27 -41
- package/dist/constants/preset.js +55 -62
- package/dist/debug.d.ts +4 -0
- package/dist/debug.js +37 -0
- package/dist/dev.js +42 -25
- package/dist/error.js +49 -42
- package/dist/hooks/build.d.ts +1 -2
- package/dist/hooks/build.js +36 -28
- package/dist/hooks/dev.js +32 -17
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +31 -16
- package/dist/hooks/misc.d.ts +5 -2
- package/dist/hooks/misc.js +31 -12
- package/dist/index.d.ts +2 -1
- package/dist/index.js +39 -32
- package/dist/locale/en.js +32 -17
- package/dist/locale/index.d.ts +2 -1
- package/dist/locale/index.js +31 -24
- package/dist/locale/zh.js +32 -17
- package/dist/plugins.js +28 -13
- package/dist/types/color.js +15 -5
- package/dist/types/command.d.ts +3 -3
- package/dist/types/command.js +15 -5
- package/dist/types/config/copy.js +15 -5
- package/dist/types/config/dev.js +15 -5
- package/dist/types/config/index.d.ts +87 -52
- package/dist/types/config/index.js +24 -6
- package/dist/types/config/style.d.ts +58 -6
- package/dist/types/config/style.js +15 -5
- package/dist/types/context.js +15 -5
- package/dist/types/dts.d.ts +14 -3
- package/dist/types/dts.js +15 -5
- package/dist/types/esbuild.d.ts +107 -0
- package/dist/types/esbuild.js +32 -0
- package/dist/types/hooks.js +15 -5
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +32 -11
- package/dist/types/legacyConfig/index.js +15 -5
- package/dist/types/legacyConfig/output.d.ts +4 -4
- package/dist/types/legacyConfig/output.js +15 -5
- package/dist/types/legacyConfig/source.js +15 -5
- package/dist/types/legacyConfig/tools.js +15 -5
- package/dist/utils/assert.d.ts +5 -0
- package/dist/utils/assert.js +50 -0
- package/dist/utils/builder.d.ts +10 -14
- package/dist/utils/builder.js +59 -59
- package/dist/utils/common.d.ts +1 -1
- package/dist/utils/common.js +25 -17
- package/dist/utils/dts.d.ts +26 -9
- package/dist/utils/dts.js +98 -64
- package/dist/utils/hash.d.ts +2 -0
- package/dist/utils/hash.js +31 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +42 -0
- package/dist/utils/input.js +47 -24
- package/dist/utils/log.d.ts +1 -2
- package/dist/utils/log.js +36 -20
- package/dist/utils/map.d.ts +13 -0
- package/dist/utils/map.js +58 -0
- package/dist/utils/onExit.js +35 -11
- package/dist/utils/print.d.ts +2 -2
- package/dist/utils/print.js +52 -49
- package/dist/utils/style.d.ts +5 -23
- package/dist/utils/style.js +57 -37
- package/dist/utils/tspath.js +114 -0
- package/package.json +64 -50
- package/vitest.config.ts +20 -0
- package/dist/build.js.map +0 -1
- package/dist/builder/build.js.map +0 -1
- package/dist/builder/clear.js.map +0 -1
- package/dist/builder/copy.js.map +0 -1
- package/dist/builder/dts/index.js.map +0 -1
- package/dist/builder/dts/rollup.js.map +0 -1
- package/dist/builder/dts/tsc.js.map +0 -1
- package/dist/builder/index.js.map +0 -1
- package/dist/builder/platform.js.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/command.js.map +0 -1
- package/dist/config/defineConfig.js.map +0 -1
- package/dist/config/legacySchema.js.map +0 -1
- package/dist/config/merge.js.map +0 -1
- package/dist/config/normalize.js.map +0 -1
- package/dist/config/schema.js.map +0 -1
- package/dist/config/transformLegacyConfig.js.map +0 -1
- package/dist/config/valid.js.map +0 -1
- package/dist/constants/build.js.map +0 -1
- package/dist/constants/color.js.map +0 -1
- package/dist/constants/dts.js.map +0 -1
- package/dist/constants/file.js.map +0 -1
- package/dist/constants/legacy-preset.js.map +0 -1
- package/dist/constants/log.js.map +0 -1
- package/dist/constants/preset.js.map +0 -1
- package/dist/dev.js.map +0 -1
- package/dist/error.js.map +0 -1
- package/dist/hooks/build.js.map +0 -1
- package/dist/hooks/dev.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/misc.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/locale/en.js.map +0 -1
- package/dist/locale/index.js.map +0 -1
- package/dist/locale/zh.js.map +0 -1
- package/dist/plugins.js.map +0 -1
- package/dist/types/color.js.map +0 -1
- package/dist/types/command.js.map +0 -1
- package/dist/types/config/copy.js.map +0 -1
- package/dist/types/config/dev.js.map +0 -1
- package/dist/types/config/index.js.map +0 -1
- package/dist/types/config/style.js.map +0 -1
- package/dist/types/context.js.map +0 -1
- package/dist/types/dts.js.map +0 -1
- package/dist/types/hooks.js.map +0 -1
- package/dist/types/index.js.map +0 -1
- package/dist/types/legacyConfig/index.js.map +0 -1
- package/dist/types/legacyConfig/output.js.map +0 -1
- package/dist/types/legacyConfig/source.js.map +0 -1
- package/dist/types/legacyConfig/tools.js.map +0 -1
- package/dist/types/utils.d.ts +0 -5
- package/dist/types/utils.js +0 -4
- package/dist/utils/builder.js.map +0 -1
- package/dist/utils/common.js.map +0 -1
- package/dist/utils/context.d.ts +0 -7
- package/dist/utils/context.js +0 -23
- package/dist/utils/context.js.map +0 -1
- package/dist/utils/dts.js.map +0 -1
- package/dist/utils/input.js.map +0 -1
- package/dist/utils/language.d.ts +0 -1
- package/dist/utils/language.js +0 -22
- package/dist/utils/language.js.map +0 -1
- package/dist/utils/libuild-plugin.d.ts +0 -3
- package/dist/utils/libuild-plugin.js +0 -31
- package/dist/utils/libuild-plugin.js.map +0 -1
- package/dist/utils/log.js.map +0 -1
- package/dist/utils/onExit.js.map +0 -1
- package/dist/utils/path.d.ts +0 -1
- package/dist/utils/path.js +0 -19
- package/dist/utils/path.js.map +0 -1
- package/dist/utils/print.js.map +0 -1
- package/dist/utils/style.js.map +0 -1
- package/dist/utils/tspathsTransform.js +0 -91
- package/dist/utils/tspathsTransform.js.map +0 -1
- /package/dist/utils/{tspathsTransform.d.ts → tspath.d.ts} +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ImportKind, Platform } from 'esbuild';
|
|
2
|
+
/**
|
|
3
|
+
* supports require js plugin in less file
|
|
4
|
+
*/
|
|
5
|
+
export declare const cssExtensions: string[];
|
|
6
|
+
export declare const createResolver: (options: ResolverOptions) => (id: string, dir: string, kind?: ImportKind) => string;
|
|
7
|
+
interface ResolverOptions {
|
|
8
|
+
platform: Platform;
|
|
9
|
+
resolveType: 'js' | 'css';
|
|
10
|
+
extensions: string[];
|
|
11
|
+
root: string;
|
|
12
|
+
alias: Record<string, string>;
|
|
13
|
+
tsconfig: string;
|
|
14
|
+
mainFields: string[];
|
|
15
|
+
preferRelative?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,125 @@
|
|
|
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 resolve_exports = {};
|
|
30
|
+
__export(resolve_exports, {
|
|
31
|
+
createResolver: () => createResolver,
|
|
32
|
+
cssExtensions: () => cssExtensions
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(resolve_exports);
|
|
35
|
+
var import_fs = __toESM(require("fs"));
|
|
36
|
+
var import_enhanced_resolve = require("enhanced-resolve");
|
|
37
|
+
var import_tsconfig_paths_webpack_plugin = __toESM(require("tsconfig-paths-webpack-plugin"));
|
|
38
|
+
const cssExtensions = [
|
|
39
|
+
".less",
|
|
40
|
+
".css",
|
|
41
|
+
".sass",
|
|
42
|
+
".scss",
|
|
43
|
+
".js"
|
|
44
|
+
];
|
|
45
|
+
function createEnhancedResolve(options) {
|
|
46
|
+
const plugins = [];
|
|
47
|
+
const { tsconfig } = options;
|
|
48
|
+
if (import_fs.default.existsSync(tsconfig)) {
|
|
49
|
+
plugins.push(new import_tsconfig_paths_webpack_plugin.default({
|
|
50
|
+
baseUrl: options.root,
|
|
51
|
+
configFile: tsconfig
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
const resolveOptions = {
|
|
55
|
+
aliasFields: options.platform === "browser" ? [
|
|
56
|
+
"browser"
|
|
57
|
+
] : [],
|
|
58
|
+
FileSystem: new import_enhanced_resolve.CachedInputFileSystem(import_fs.default, 4e3),
|
|
59
|
+
mainFields: options.mainFields,
|
|
60
|
+
mainFiles: [
|
|
61
|
+
"index"
|
|
62
|
+
],
|
|
63
|
+
extensions: options.extensions,
|
|
64
|
+
preferRelative: options.preferRelative,
|
|
65
|
+
addMatchAll: false,
|
|
66
|
+
plugins,
|
|
67
|
+
alias: options.alias
|
|
68
|
+
};
|
|
69
|
+
const resolveSync = (dir, id) => import_enhanced_resolve.create.sync({
|
|
70
|
+
...resolveOptions,
|
|
71
|
+
conditionNames: [
|
|
72
|
+
options.platform,
|
|
73
|
+
"require",
|
|
74
|
+
"module"
|
|
75
|
+
]
|
|
76
|
+
})(dir, id);
|
|
77
|
+
const esmResolveSync = (dir, id) => import_enhanced_resolve.create.sync({
|
|
78
|
+
...resolveOptions,
|
|
79
|
+
conditionNames: [
|
|
80
|
+
options.platform,
|
|
81
|
+
"import",
|
|
82
|
+
"module"
|
|
83
|
+
]
|
|
84
|
+
})(dir, id);
|
|
85
|
+
return {
|
|
86
|
+
resolveSync,
|
|
87
|
+
esmResolveSync
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
const createResolver = (options) => {
|
|
91
|
+
const resolveCache = /* @__PURE__ */ new Map();
|
|
92
|
+
const { resolveSync, esmResolveSync } = createEnhancedResolve(options);
|
|
93
|
+
const resolver = (id, dir, kind) => {
|
|
94
|
+
const cacheKey = id + dir + (kind || "");
|
|
95
|
+
const cacheResult = resolveCache.get(cacheKey);
|
|
96
|
+
if (cacheResult) {
|
|
97
|
+
return cacheResult;
|
|
98
|
+
}
|
|
99
|
+
let result;
|
|
100
|
+
if (options.resolveType === "js") {
|
|
101
|
+
if (kind === "import-statement" || kind === "dynamic-import") {
|
|
102
|
+
result = esmResolveSync(dir, id);
|
|
103
|
+
} else {
|
|
104
|
+
result = resolveSync(dir, id);
|
|
105
|
+
}
|
|
106
|
+
} else {
|
|
107
|
+
try {
|
|
108
|
+
result = resolveSync(dir, id);
|
|
109
|
+
} catch (err) {
|
|
110
|
+
result = resolveSync(dir, id.replace(/^~/, ""));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!result) {
|
|
114
|
+
throw new Error(`can not resolve ${id} from ${dir}`);
|
|
115
|
+
}
|
|
116
|
+
resolveCache.set(cacheKey, result);
|
|
117
|
+
return result;
|
|
118
|
+
};
|
|
119
|
+
return resolver;
|
|
120
|
+
};
|
|
121
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
122
|
+
0 && (module.exports = {
|
|
123
|
+
createResolver,
|
|
124
|
+
cssExtensions
|
|
125
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { SourceMap, ISourcemapContext } from '../../types';
|
|
2
|
+
export declare class SourcemapContext implements ISourcemapContext {
|
|
3
|
+
private enableSourceMap?;
|
|
4
|
+
private sourceMapChain;
|
|
5
|
+
private sourceMapDirty;
|
|
6
|
+
private cachedInlineSourceMap;
|
|
7
|
+
private cachedSourceMap;
|
|
8
|
+
private pluginIdMap;
|
|
9
|
+
constructor(enableSourceMap?: boolean | undefined);
|
|
10
|
+
private markSourceMapStatus;
|
|
11
|
+
addSourceMap(pluginId: number, map?: SourceMap): void;
|
|
12
|
+
getInlineSourceMap(): string;
|
|
13
|
+
getSourceMap(): SourceMap | undefined;
|
|
14
|
+
getSourceMapChain(): SourceMap[];
|
|
15
|
+
genPluginId(name: string): number;
|
|
16
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var sourcemap_exports = {};
|
|
20
|
+
__export(sourcemap_exports, {
|
|
21
|
+
SourcemapContext: () => SourcemapContext
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(sourcemap_exports);
|
|
24
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
25
|
+
var import_utils = require("../../utils");
|
|
26
|
+
class SourcemapContext {
|
|
27
|
+
markSourceMapStatus(dirty) {
|
|
28
|
+
this.sourceMapDirty = dirty;
|
|
29
|
+
}
|
|
30
|
+
addSourceMap(pluginId, map) {
|
|
31
|
+
if (this.enableSourceMap && this.sourceMapChain[pluginId] !== map) {
|
|
32
|
+
this.sourceMapChain[pluginId] = map;
|
|
33
|
+
this.markSourceMapStatus(true);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
getInlineSourceMap() {
|
|
37
|
+
if (this.sourceMapDirty && this.enableSourceMap) {
|
|
38
|
+
const effectMapList = this.getSourceMapChain().reverse();
|
|
39
|
+
if (effectMapList.length > 0) {
|
|
40
|
+
this.cachedInlineSourceMap = (0, import_utils.mergeMaps)(effectMapList).toComment();
|
|
41
|
+
} else {
|
|
42
|
+
this.cachedInlineSourceMap = "";
|
|
43
|
+
}
|
|
44
|
+
this.markSourceMapStatus(false);
|
|
45
|
+
}
|
|
46
|
+
return this.cachedInlineSourceMap;
|
|
47
|
+
}
|
|
48
|
+
getSourceMap() {
|
|
49
|
+
if (this.sourceMapDirty && this.enableSourceMap) {
|
|
50
|
+
const effectMapList = this.getSourceMapChain().reverse();
|
|
51
|
+
if (effectMapList.length > 0) {
|
|
52
|
+
this.cachedSourceMap = (0, import_utils.mergeMaps)(effectMapList).toMap();
|
|
53
|
+
}
|
|
54
|
+
this.markSourceMapStatus(false);
|
|
55
|
+
}
|
|
56
|
+
return this.cachedSourceMap;
|
|
57
|
+
}
|
|
58
|
+
getSourceMapChain() {
|
|
59
|
+
return this.sourceMapChain.filter((m) => Boolean(m && m.mappings));
|
|
60
|
+
}
|
|
61
|
+
genPluginId(name) {
|
|
62
|
+
if (this.pluginIdMap.has(name)) {
|
|
63
|
+
return this.pluginIdMap.get(name);
|
|
64
|
+
}
|
|
65
|
+
const id = this.sourceMapChain.length;
|
|
66
|
+
this.pluginIdMap.set(name, id);
|
|
67
|
+
return id;
|
|
68
|
+
}
|
|
69
|
+
constructor(enableSourceMap) {
|
|
70
|
+
(0, import_define_property._)(this, "enableSourceMap", void 0);
|
|
71
|
+
(0, import_define_property._)(this, "sourceMapChain", void 0);
|
|
72
|
+
(0, import_define_property._)(this, "sourceMapDirty", void 0);
|
|
73
|
+
(0, import_define_property._)(this, "cachedInlineSourceMap", void 0);
|
|
74
|
+
(0, import_define_property._)(this, "cachedSourceMap", void 0);
|
|
75
|
+
(0, import_define_property._)(this, "pluginIdMap", void 0);
|
|
76
|
+
this.enableSourceMap = enableSourceMap;
|
|
77
|
+
this.sourceMapChain = [];
|
|
78
|
+
this.sourceMapDirty = false;
|
|
79
|
+
this.cachedInlineSourceMap = "";
|
|
80
|
+
this.pluginIdMap = /* @__PURE__ */ new Map();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
SourcemapContext
|
|
86
|
+
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ITransformContext, CacheValue } from '../../types';
|
|
2
|
+
import { SourcemapContext } from './sourcemap';
|
|
3
|
+
export declare class TransformContext extends SourcemapContext implements ITransformContext {
|
|
4
|
+
private cachedTransformResult;
|
|
5
|
+
addTransformResult(pluginId: number, result: CacheValue): void;
|
|
6
|
+
getValidCache(pluginId: number, code: string): CacheValue | undefined;
|
|
7
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var transform_exports = {};
|
|
20
|
+
__export(transform_exports, {
|
|
21
|
+
TransformContext: () => TransformContext
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(transform_exports);
|
|
24
|
+
var import_define_property = require("@swc/helpers/_/_define_property");
|
|
25
|
+
var import_sourcemap = require("./sourcemap");
|
|
26
|
+
class TransformContext extends import_sourcemap.SourcemapContext {
|
|
27
|
+
addTransformResult(pluginId, result) {
|
|
28
|
+
this.cachedTransformResult.set(pluginId, result);
|
|
29
|
+
this.addSourceMap(pluginId, result.map);
|
|
30
|
+
}
|
|
31
|
+
getValidCache(pluginId, code) {
|
|
32
|
+
const cache = this.cachedTransformResult.get(pluginId);
|
|
33
|
+
if (cache && cache.originCode === code) {
|
|
34
|
+
return cache;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
constructor(...args) {
|
|
38
|
+
super(...args);
|
|
39
|
+
(0, import_define_property._)(this, "cachedTransformResult", /* @__PURE__ */ new Map());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
43
|
+
0 && (module.exports = {
|
|
44
|
+
TransformContext
|
|
45
|
+
});
|
|
@@ -0,0 +1,115 @@
|
|
|
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 watch_exports = {};
|
|
30
|
+
__export(watch_exports, {
|
|
31
|
+
initWatcher: () => initWatcher
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(watch_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
const initWatcher = (compiler) => {
|
|
37
|
+
const { config, api } = compiler;
|
|
38
|
+
const watch = import_utils.chokidar.watch([
|
|
39
|
+
compiler.context.root
|
|
40
|
+
], {
|
|
41
|
+
useFsEvents: false,
|
|
42
|
+
ignored: [
|
|
43
|
+
"**/node_modules",
|
|
44
|
+
"**/.gitignore",
|
|
45
|
+
"**/.git",
|
|
46
|
+
compiler.config.outDir
|
|
47
|
+
],
|
|
48
|
+
cwd: compiler.context.root
|
|
49
|
+
});
|
|
50
|
+
compiler.watcher = watch;
|
|
51
|
+
let running = false;
|
|
52
|
+
let needReRun = false;
|
|
53
|
+
const handleLink = async (filePath, type) => {
|
|
54
|
+
const { config: config2, context: { root } } = compiler;
|
|
55
|
+
const { buildType, input, sourceDir } = config2;
|
|
56
|
+
const absFilePath = import_path.default.resolve(root, filePath);
|
|
57
|
+
let shouldRebuild = false;
|
|
58
|
+
if (buildType === "bundleless" && Array.isArray(input)) {
|
|
59
|
+
if (type === "add") {
|
|
60
|
+
shouldRebuild = absFilePath.startsWith(sourceDir);
|
|
61
|
+
} else {
|
|
62
|
+
shouldRebuild = input.some((item) => item === filePath);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
if (shouldRebuild) {
|
|
66
|
+
const text = type === "add" ? "added" : "unlinked";
|
|
67
|
+
import_utils.logger.info(`${import_utils.chalk.underline(filePath)} ${text}`);
|
|
68
|
+
if (type === "unlink") {
|
|
69
|
+
input.splice(input.indexOf(filePath), 1);
|
|
70
|
+
} else {
|
|
71
|
+
input.push(filePath);
|
|
72
|
+
}
|
|
73
|
+
if (running) {
|
|
74
|
+
needReRun = true;
|
|
75
|
+
} else {
|
|
76
|
+
running = true;
|
|
77
|
+
await compiler.reBuild("link", config2);
|
|
78
|
+
running = false;
|
|
79
|
+
if (needReRun) {
|
|
80
|
+
needReRun = false;
|
|
81
|
+
await compiler.reBuild("link", config2);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const handleAdd = async (filePath) => {
|
|
87
|
+
return handleLink(filePath, "add");
|
|
88
|
+
};
|
|
89
|
+
const handleUnlink = async (filePath) => {
|
|
90
|
+
return handleLink(filePath, "unlink");
|
|
91
|
+
};
|
|
92
|
+
const handleChange = async (filePath, _events) => {
|
|
93
|
+
const { context: { root }, watchedFiles } = compiler;
|
|
94
|
+
if (watchedFiles.has(import_path.default.resolve(root, filePath))) {
|
|
95
|
+
import_utils.logger.info(`File changed: ${import_utils.chalk.dim(filePath)}`);
|
|
96
|
+
const runner = api.useHookRunners();
|
|
97
|
+
runner.buildWatchJs({
|
|
98
|
+
buildConfig: config
|
|
99
|
+
});
|
|
100
|
+
await compiler.reBuild("change", config);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
watch.on("ready", () => {
|
|
104
|
+
watch.on("change", handleChange);
|
|
105
|
+
watch.on("add", handleAdd);
|
|
106
|
+
watch.on("unlink", handleUnlink);
|
|
107
|
+
});
|
|
108
|
+
watch.once("restart", () => {
|
|
109
|
+
watch.removeListener("change", handleChange);
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
+
0 && (module.exports = {
|
|
114
|
+
initWatcher
|
|
115
|
+
});
|
|
@@ -0,0 +1,89 @@
|
|
|
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 write_file_exports = {};
|
|
30
|
+
__export(write_file_exports, {
|
|
31
|
+
writeFile: () => writeFile
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(write_file_exports);
|
|
34
|
+
var import_path = __toESM(require("path"));
|
|
35
|
+
var import_utils = require("@modern-js/utils");
|
|
36
|
+
var import_convert_source_map = __toESM(require("convert-source-map"));
|
|
37
|
+
const SOURCE_MAPPING_URL = "sourceMappingURL";
|
|
38
|
+
let preOutputChunk = null;
|
|
39
|
+
function appendSourceMapURLLink(options) {
|
|
40
|
+
return `${options.code}
|
|
41
|
+
//# ${SOURCE_MAPPING_URL}=${options.filename}.map`;
|
|
42
|
+
}
|
|
43
|
+
function appendSourceMapInline(options) {
|
|
44
|
+
return `${options.code}
|
|
45
|
+
//# ${SOURCE_MAPPING_URL}=data:application/json;charset=utf-8;base64,${options.map}`;
|
|
46
|
+
}
|
|
47
|
+
function chunkHasChanged(key, chunk) {
|
|
48
|
+
if (preOutputChunk) {
|
|
49
|
+
const preChunk = preOutputChunk.get(key);
|
|
50
|
+
if (preChunk && preChunk.contents === chunk.contents) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
const writeFile = async (compiler) => {
|
|
57
|
+
for (const [key, value] of compiler.outputChunk.entries()) {
|
|
58
|
+
if (!chunkHasChanged(key, value)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
const absPath = import_path.default.resolve(compiler.config.outDir, key);
|
|
62
|
+
await import_utils.fs.ensureDir(import_path.default.dirname(absPath));
|
|
63
|
+
if (value.type === "chunk" && value.map) {
|
|
64
|
+
if (compiler.config.sourceMap === false || compiler.config.sourceMap === "external") {
|
|
65
|
+
await import_utils.fs.writeFile(absPath, value.contents);
|
|
66
|
+
} else if (compiler.config.sourceMap === true) {
|
|
67
|
+
await import_utils.fs.writeFile(absPath, appendSourceMapURLLink({
|
|
68
|
+
code: value.contents,
|
|
69
|
+
filename: import_path.default.basename(absPath)
|
|
70
|
+
}));
|
|
71
|
+
} else if (compiler.config.sourceMap === "inline") {
|
|
72
|
+
await import_utils.fs.writeFile(absPath, appendSourceMapInline({
|
|
73
|
+
code: value.contents,
|
|
74
|
+
map: import_convert_source_map.default.fromObject(value.map).toBase64()
|
|
75
|
+
}));
|
|
76
|
+
}
|
|
77
|
+
if (compiler.config.sourceMap === true || compiler.config.sourceMap === "external") {
|
|
78
|
+
await import_utils.fs.writeFile(`${absPath}.map`, JSON.stringify(value.map));
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
await import_utils.fs.writeFile(absPath, value.contents);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
preOutputChunk = compiler.outputChunk;
|
|
85
|
+
};
|
|
86
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
87
|
+
0 && (module.exports = {
|
|
88
|
+
writeFile
|
|
89
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ICompiler, LoadResult, SvgrOptions } from '../../types';
|
|
3
|
+
export declare const asset: {
|
|
4
|
+
name: string;
|
|
5
|
+
apply(compiler: ICompiler): void;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param this Compiler
|
|
10
|
+
* @param assetPath Absolute path of the asset
|
|
11
|
+
* @param rebaseFrom Absolute path of the file which use asset
|
|
12
|
+
* @param calledOnLoad called in load hooks
|
|
13
|
+
* @returns dataurl or path
|
|
14
|
+
*/
|
|
15
|
+
export declare function getAssetContents(this: ICompiler, assetPath: string, rebaseFrom: string, calledOnLoad?: boolean): Promise<{
|
|
16
|
+
contents: string | Buffer;
|
|
17
|
+
loader: "copy" | "text";
|
|
18
|
+
}>;
|
|
19
|
+
export declare function loadSvgr(path: string, options: boolean | SvgrOptions): Promise<LoadResult | undefined>;
|
|
@@ -0,0 +1,149 @@
|
|
|
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 name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], 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 asset_exports = {};
|
|
30
|
+
__export(asset_exports, {
|
|
31
|
+
asset: () => asset,
|
|
32
|
+
getAssetContents: () => getAssetContents,
|
|
33
|
+
loadSvgr: () => loadSvgr
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(asset_exports);
|
|
36
|
+
var import_path = require("path");
|
|
37
|
+
var import_fs = __toESM(require("fs"));
|
|
38
|
+
var import_pluginutils = require("@rollup/pluginutils");
|
|
39
|
+
var import_core = require("@svgr/core");
|
|
40
|
+
var import_plugin_svgo = __toESM(require("@svgr/plugin-svgo"));
|
|
41
|
+
var import_plugin_jsx = __toESM(require("@svgr/plugin-jsx"));
|
|
42
|
+
var import_file = require("../../constants/file");
|
|
43
|
+
var import_utils = require("../../utils");
|
|
44
|
+
const name = "asset";
|
|
45
|
+
const SVG_REGEXP = /\.svg$/;
|
|
46
|
+
const asset = {
|
|
47
|
+
name,
|
|
48
|
+
apply(compiler) {
|
|
49
|
+
compiler.hooks.load.tapPromise({
|
|
50
|
+
name
|
|
51
|
+
}, async (args) => {
|
|
52
|
+
if (import_file.assetExt.find((ext) => ext === (0, import_path.extname)(args.path))) {
|
|
53
|
+
const { buildType, outDir, sourceDir, asset: asset2 } = compiler.config;
|
|
54
|
+
const svgrResult = await loadSvgr(args.path, asset2.svgr);
|
|
55
|
+
if (svgrResult) {
|
|
56
|
+
return svgrResult;
|
|
57
|
+
}
|
|
58
|
+
const rebaseFrom = buildType === "bundle" ? outDir : (0, import_path.join)(outDir, (0, import_path.relative)(sourceDir, (0, import_path.dirname)(args.path)));
|
|
59
|
+
const { contents, loader } = await getAssetContents.apply(compiler, [
|
|
60
|
+
args.path,
|
|
61
|
+
rebaseFrom,
|
|
62
|
+
true
|
|
63
|
+
]);
|
|
64
|
+
return {
|
|
65
|
+
contents,
|
|
66
|
+
loader
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
function encodeSVG(buffer) {
|
|
73
|
+
return encodeURIComponent(buffer.toString("utf-8").replace(/[\n\r]/gim, "").replace(/\t/gim, " ").replace(/<!--(.*(?=-->))-->/gim, "").replace(/'/gim, "\\i")).replace(/\(/g, "%28").replace(/\)/g, "%29");
|
|
74
|
+
}
|
|
75
|
+
async function getAssetContents(assetPath, rebaseFrom, calledOnLoad) {
|
|
76
|
+
const fileContent = await import_fs.default.promises.readFile(assetPath);
|
|
77
|
+
const { buildType, format, outDir } = this.config;
|
|
78
|
+
const { limit, path, publicPath } = this.config.asset;
|
|
79
|
+
const hash = (0, import_utils.getHash)(fileContent, null).slice(0, 8);
|
|
80
|
+
const outputFileName = (0, import_path.basename)(assetPath).split(".").join(`.${hash}.`);
|
|
81
|
+
const outputFilePath = (0, import_path.resolve)(outDir, path, outputFileName);
|
|
82
|
+
const relativePath = (0, import_path.relative)(rebaseFrom, outputFilePath);
|
|
83
|
+
const normalizedRelativePath = (0, import_utils.normalizeSlashes)(relativePath.startsWith("..") ? relativePath : `./${relativePath}`);
|
|
84
|
+
const normalizedPublicPath = `${typeof publicPath === "function" ? publicPath(assetPath) : publicPath}${path}/${outputFileName}`;
|
|
85
|
+
let emitAsset = true;
|
|
86
|
+
let contents = normalizedPublicPath;
|
|
87
|
+
let loader = "text";
|
|
88
|
+
if (buildType === "bundle") {
|
|
89
|
+
if (fileContent.length <= limit) {
|
|
90
|
+
const mimetype = (await Promise.resolve().then(() => __toESM(require("@modern-js/utils/mime-types")))).default.lookup(assetPath);
|
|
91
|
+
const isSVG = mimetype === "image/svg+xml";
|
|
92
|
+
const data = isSVG ? encodeSVG(fileContent) : fileContent.toString("base64");
|
|
93
|
+
const encoding = isSVG ? "" : ";base64";
|
|
94
|
+
contents = `data:${mimetype}${encoding},${data}`;
|
|
95
|
+
loader = "text";
|
|
96
|
+
emitAsset = false;
|
|
97
|
+
} else if ((format === "esm" || format === "cjs") && !publicPath) {
|
|
98
|
+
contents = calledOnLoad ? fileContent : normalizedRelativePath;
|
|
99
|
+
loader = calledOnLoad ? "copy" : "text";
|
|
100
|
+
emitAsset = !calledOnLoad;
|
|
101
|
+
}
|
|
102
|
+
} else {
|
|
103
|
+
contents = normalizedRelativePath;
|
|
104
|
+
}
|
|
105
|
+
if (emitAsset) {
|
|
106
|
+
this.emitAsset(outputFilePath, {
|
|
107
|
+
type: "asset",
|
|
108
|
+
fileName: outputFilePath,
|
|
109
|
+
contents: fileContent,
|
|
110
|
+
originalFileName: assetPath
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
return {
|
|
114
|
+
contents,
|
|
115
|
+
loader
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
async function loadSvgr(path, options) {
|
|
119
|
+
if (!options) {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
const config = typeof options === "boolean" ? {} : options;
|
|
123
|
+
const filter = (0, import_pluginutils.createFilter)(config.include || SVG_REGEXP, config.exclude);
|
|
124
|
+
if (!filter(path)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const loader = "jsx";
|
|
128
|
+
const text = import_fs.default.readFileSync(path, "utf8");
|
|
129
|
+
const jsCode = await (0, import_core.transform)(text, config, {
|
|
130
|
+
filePath: path,
|
|
131
|
+
caller: {
|
|
132
|
+
name: "svgr",
|
|
133
|
+
defaultPlugins: [
|
|
134
|
+
import_plugin_svgo.default,
|
|
135
|
+
import_plugin_jsx.default
|
|
136
|
+
]
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return {
|
|
140
|
+
contents: jsCode,
|
|
141
|
+
loader
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
145
|
+
0 && (module.exports = {
|
|
146
|
+
asset,
|
|
147
|
+
getAssetContents,
|
|
148
|
+
loadSvgr
|
|
149
|
+
});
|