@analogjs/vite-plugin-angular 3.0.0-alpha.4 → 3.0.0-alpha.40
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/README.md +28 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.d.ts +2 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js +49 -0
- package/migrations/migrate-setup-vitest/migrate-setup-vitest.js.map +1 -0
- package/migrations/migration.json +7 -1
- package/migrations/migrations.json +9 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.d.ts +2 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js +36 -0
- package/migrations/update-3-0-0/migrate-setup-vitest.js.map +1 -0
- package/package.json +25 -12
- package/src/index.d.ts +3 -2
- package/src/index.js +6 -2
- package/src/index.js.map +1 -1
- package/src/lib/angular-build-optimizer-plugin.d.ts +4 -4
- package/src/lib/angular-build-optimizer-plugin.js +48 -62
- package/src/lib/angular-build-optimizer-plugin.js.map +1 -1
- package/src/lib/angular-jit-plugin.d.ts +3 -3
- package/src/lib/angular-jit-plugin.js +42 -37
- package/src/lib/angular-jit-plugin.js.map +1 -1
- package/src/lib/angular-pending-tasks.plugin.d.ts +7 -7
- package/src/lib/angular-pending-tasks.plugin.js +17 -18
- package/src/lib/angular-pending-tasks.plugin.js.map +1 -1
- package/src/lib/angular-vite-plugin.d.ts +250 -40
- package/src/lib/angular-vite-plugin.js +2216 -964
- package/src/lib/angular-vite-plugin.js.map +1 -1
- package/src/lib/angular-vitest-plugin.d.ts +19 -15
- package/src/lib/angular-vitest-plugin.js +99 -114
- package/src/lib/angular-vitest-plugin.js.map +1 -1
- package/src/lib/compiler/angular-version.d.ts +19 -0
- package/src/lib/compiler/angular-version.js +16 -0
- package/src/lib/compiler/angular-version.js.map +1 -0
- package/src/lib/compiler/class-field-lowering.d.ts +23 -0
- package/src/lib/compiler/class-field-lowering.js +131 -0
- package/src/lib/compiler/class-field-lowering.js.map +1 -0
- package/src/lib/compiler/compile.d.ts +44 -0
- package/src/lib/compiler/compile.js +731 -0
- package/src/lib/compiler/compile.js.map +1 -0
- package/src/lib/compiler/constants.d.ts +18 -0
- package/src/lib/compiler/constants.js +52 -0
- package/src/lib/compiler/constants.js.map +1 -0
- package/src/lib/compiler/debug.d.ts +22 -0
- package/src/lib/compiler/debug.js +20 -0
- package/src/lib/compiler/debug.js.map +1 -0
- package/src/lib/compiler/defer.d.ts +47 -0
- package/src/lib/compiler/defer.js +138 -0
- package/src/lib/compiler/defer.js.map +1 -0
- package/src/lib/compiler/dts-reader.d.ts +35 -0
- package/src/lib/compiler/dts-reader.js +365 -0
- package/src/lib/compiler/dts-reader.js.map +1 -0
- package/src/lib/compiler/hmr.d.ts +16 -0
- package/src/lib/compiler/hmr.js +69 -0
- package/src/lib/compiler/hmr.js.map +1 -0
- package/src/lib/compiler/index.d.ts +7 -0
- package/src/lib/compiler/index.js +7 -0
- package/src/lib/compiler/jit-metadata.d.ts +14 -0
- package/src/lib/compiler/jit-metadata.js +146 -0
- package/src/lib/compiler/jit-metadata.js.map +1 -0
- package/src/lib/compiler/jit-transform.d.ts +24 -0
- package/src/lib/compiler/jit-transform.js +200 -0
- package/src/lib/compiler/jit-transform.js.map +1 -0
- package/src/lib/compiler/js-emitter.d.ts +10 -0
- package/src/lib/compiler/js-emitter.js +420 -0
- package/src/lib/compiler/js-emitter.js.map +1 -0
- package/src/lib/compiler/metadata.d.ts +45 -0
- package/src/lib/compiler/metadata.js +633 -0
- package/src/lib/compiler/metadata.js.map +1 -0
- package/src/lib/compiler/registry.d.ts +49 -0
- package/src/lib/compiler/registry.js +164 -0
- package/src/lib/compiler/registry.js.map +1 -0
- package/src/lib/compiler/resource-inliner.d.ts +21 -0
- package/src/lib/compiler/resource-inliner.js +152 -0
- package/src/lib/compiler/resource-inliner.js.map +1 -0
- package/src/lib/compiler/style-ast.d.ts +8 -0
- package/src/lib/compiler/style-ast.js +54 -0
- package/src/lib/compiler/style-ast.js.map +1 -0
- package/src/lib/compiler/styles.d.ts +13 -0
- package/src/lib/compiler/test-helpers.d.ts +7 -0
- package/src/lib/compiler/type-elision.d.ts +26 -0
- package/src/lib/compiler/type-elision.js +211 -0
- package/src/lib/compiler/type-elision.js.map +1 -0
- package/src/lib/compiler/utils.d.ts +10 -0
- package/src/lib/compiler/utils.js +35 -0
- package/src/lib/compiler/utils.js.map +1 -0
- package/src/lib/compiler-plugin.d.ts +11 -11
- package/src/lib/compiler-plugin.js +43 -44
- package/src/lib/compiler-plugin.js.map +1 -1
- package/src/lib/component-resolvers.d.ts +23 -5
- package/src/lib/component-resolvers.js +153 -63
- package/src/lib/component-resolvers.js.map +1 -1
- package/src/lib/fast-compile-plugin.d.ts +14 -0
- package/src/lib/fast-compile-plugin.js +270 -0
- package/src/lib/fast-compile-plugin.js.map +1 -0
- package/src/lib/host.d.ts +10 -8
- package/src/lib/host.js +111 -101
- package/src/lib/host.js.map +1 -1
- package/src/lib/live-reload-plugin.d.ts +5 -5
- package/src/lib/live-reload-plugin.js +61 -62
- package/src/lib/live-reload-plugin.js.map +1 -1
- package/src/lib/models.d.ts +9 -9
- package/src/lib/nx-folder-plugin.d.ts +5 -5
- package/src/lib/nx-folder-plugin.js +18 -16
- package/src/lib/nx-folder-plugin.js.map +1 -1
- package/src/lib/plugins/file-replacements.plugin.d.ts +4 -4
- package/src/lib/plugins/file-replacements.plugin.js +40 -62
- package/src/lib/plugins/file-replacements.plugin.js.map +1 -1
- package/src/lib/router-plugin.d.ts +1 -1
- package/src/lib/router-plugin.js +23 -23
- package/src/lib/router-plugin.js.map +1 -1
- package/src/lib/style-pipeline.d.ts +15 -0
- package/src/lib/style-pipeline.js +31 -0
- package/src/lib/style-pipeline.js.map +1 -0
- package/src/lib/style-preprocessor.d.ts +35 -0
- package/src/lib/style-preprocessor.js +35 -0
- package/src/lib/style-preprocessor.js.map +1 -0
- package/src/lib/stylesheet-registry.d.ts +73 -0
- package/src/lib/stylesheet-registry.js +168 -0
- package/src/lib/stylesheet-registry.js.map +1 -0
- package/src/lib/tools/package.json +2 -7
- package/src/lib/tools/src/builders/vite/vite-build.impl.js +31 -38
- package/src/lib/tools/src/builders/vite/vite-build.impl.js.map +1 -1
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js +51 -62
- package/src/lib/tools/src/builders/vite-dev-server/dev-server.impl.js.map +1 -1
- package/src/lib/tools/src/index.js +0 -2
- package/src/lib/utils/compiler-plugin-options.d.ts +11 -11
- package/src/lib/utils/debug-harness.d.ts +23 -0
- package/src/lib/utils/debug-harness.js +88 -0
- package/src/lib/utils/debug-harness.js.map +1 -0
- package/src/lib/utils/debug-log-file.d.ts +5 -0
- package/src/lib/utils/debug-log-file.js +56 -0
- package/src/lib/utils/debug-log-file.js.map +1 -0
- package/src/lib/utils/debug.d.ts +28 -0
- package/src/lib/utils/debug.js +39 -0
- package/src/lib/utils/debug.js.map +1 -0
- package/src/lib/utils/devkit.d.ts +6 -6
- package/src/lib/utils/devkit.js +34 -38
- package/src/lib/utils/devkit.js.map +1 -1
- package/src/lib/utils/hmr-candidates.d.ts +28 -28
- package/src/lib/utils/plugin-config.d.ts +30 -0
- package/src/lib/utils/plugin-config.js +64 -0
- package/src/lib/utils/plugin-config.js.map +1 -0
- package/src/lib/utils/rolldown.d.ts +2 -0
- package/src/lib/utils/rolldown.js +12 -0
- package/src/lib/utils/rolldown.js.map +1 -0
- package/src/lib/utils/source-file-cache.d.ts +8 -15
- package/src/lib/utils/source-file-cache.js +35 -37
- package/src/lib/utils/source-file-cache.js.map +1 -1
- package/src/lib/utils/tailwind-reference.d.ts +12 -0
- package/src/lib/utils/tailwind-reference.js +99 -0
- package/src/lib/utils/tailwind-reference.js.map +1 -0
- package/src/lib/utils/virtual-ids.d.ts +8 -0
- package/src/lib/utils/virtual-ids.js +35 -0
- package/src/lib/utils/virtual-ids.js.map +1 -0
- package/src/lib/utils/virtual-resources.d.ts +47 -0
- package/src/lib/utils/virtual-resources.js +89 -0
- package/src/lib/utils/virtual-resources.js.map +1 -0
- package/src/test-setup.d.ts +2 -0
- package/setup-vitest.d.ts +0 -4
- package/setup-vitest.js +0 -215
- package/setup-vitest.js.map +0 -1
- package/src/lib/models.js +0 -1
- package/src/lib/models.js.map +0 -1
- package/src/lib/tools/README.md +0 -3
- package/src/lib/tools/src/index.d.ts +0 -0
- package/src/lib/tools/src/index.js.map +0 -1
- package/src/lib/utils/compiler-plugin-options.js +0 -1
- package/src/lib/utils/compiler-plugin-options.js.map +0 -1
- package/src/lib/utils/hmr-candidates.js +0 -272
- package/src/lib/utils/hmr-candidates.js.map +0 -1
package/src/lib/host.js
CHANGED
|
@@ -1,108 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
import { debugStyles } from "./utils/debug.js";
|
|
2
|
+
import { isTailwindReferenceError } from "./utils/tailwind-reference.js";
|
|
3
|
+
import { normalizeStylesheetDependencies } from "./style-preprocessor.js";
|
|
4
|
+
import { preprocessStylesheetResult, registerStylesheetContent } from "./stylesheet-registry.js";
|
|
5
|
+
import { createHash } from "node:crypto";
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import { normalizePath } from "vite";
|
|
8
|
+
//#region packages/vite-plugin-angular/src/lib/host.ts
|
|
9
|
+
function augmentHostWithResources(host, transform, options) {
|
|
10
|
+
const resourceHost = host;
|
|
11
|
+
resourceHost.readResource = async function(fileName) {
|
|
12
|
+
const filePath = normalizePath(fileName);
|
|
13
|
+
const content = this.readFile(filePath);
|
|
14
|
+
if (content === void 0) throw new Error("Unable to locate component resource: " + fileName);
|
|
15
|
+
return content;
|
|
16
|
+
};
|
|
17
|
+
resourceHost.getModifiedResourceFiles = function() {
|
|
18
|
+
return options?.sourceFileCache?.modifiedFiles;
|
|
19
|
+
};
|
|
20
|
+
resourceHost.transformResource = async function(data, context) {
|
|
21
|
+
if (context.type !== "style") return null;
|
|
22
|
+
const filename = context.resourceFile ?? context.containingFile.replace(".ts", `.${options?.inlineStylesExtension}`);
|
|
23
|
+
const preprocessed = preprocessStylesheetResult(data, filename, options.stylePreprocessor, {
|
|
24
|
+
filename,
|
|
25
|
+
containingFile: context.containingFile,
|
|
26
|
+
resourceFile: context.resourceFile ?? void 0,
|
|
27
|
+
className: context.className,
|
|
28
|
+
order: context.order,
|
|
29
|
+
inline: !context.resourceFile
|
|
30
|
+
});
|
|
31
|
+
if (options.stylesheetRegistry) {
|
|
32
|
+
const stylesheetId = registerStylesheetContent(options.stylesheetRegistry, {
|
|
33
|
+
code: preprocessed.code,
|
|
34
|
+
dependencies: normalizeStylesheetDependencies(preprocessed.dependencies),
|
|
35
|
+
diagnostics: preprocessed.diagnostics,
|
|
36
|
+
tags: preprocessed.tags,
|
|
37
|
+
containingFile: context.containingFile,
|
|
38
|
+
className: context.className,
|
|
39
|
+
order: context.order,
|
|
40
|
+
inlineStylesExtension: options.inlineStylesExtension,
|
|
41
|
+
resourceFile: context.resourceFile ?? void 0
|
|
42
|
+
});
|
|
43
|
+
debugStyles("NgtscProgram: stylesheet deferred to Vite pipeline", {
|
|
44
|
+
stylesheetId,
|
|
45
|
+
resourceFile: context.resourceFile ?? "(inline)",
|
|
46
|
+
dependencies: preprocessed.dependencies,
|
|
47
|
+
diagnostics: preprocessed.diagnostics,
|
|
48
|
+
tags: preprocessed.tags
|
|
49
|
+
});
|
|
50
|
+
return { content: stylesheetId };
|
|
51
|
+
}
|
|
52
|
+
debugStyles("NgtscProgram: stylesheet processed inline via transform", {
|
|
53
|
+
filename,
|
|
54
|
+
resourceFile: context.resourceFile ?? "(inline)",
|
|
55
|
+
dataLength: preprocessed.code.length
|
|
56
|
+
});
|
|
57
|
+
let stylesheetResult;
|
|
58
|
+
try {
|
|
59
|
+
stylesheetResult = await transform(preprocessed.code, `${filename}?direct`);
|
|
60
|
+
} catch (e) {
|
|
61
|
+
if (isTailwindReferenceError(e)) throw e;
|
|
62
|
+
debugStyles("NgtscProgram: stylesheet transform error", {
|
|
63
|
+
filename,
|
|
64
|
+
resourceFile: context.resourceFile ?? "(inline)",
|
|
65
|
+
error: String(e)
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
if (!stylesheetResult?.code) return null;
|
|
69
|
+
return { content: stylesheetResult.code };
|
|
70
|
+
};
|
|
71
|
+
resourceHost.resourceNameToFileName = function(resourceName, containingFile, fallbackResolve) {
|
|
72
|
+
const resolvedPath = normalizePath(fallbackResolve ? fallbackResolve(path.dirname(containingFile), resourceName) : path.join(path.dirname(containingFile), resourceName));
|
|
73
|
+
if (!options.stylesheetRegistry || !hasStyleExtension(resolvedPath)) return resolvedPath;
|
|
74
|
+
const filename = createHash("sha256").update(resolvedPath).digest("hex") + path.extname(resolvedPath);
|
|
75
|
+
options.stylesheetRegistry.registerExternalRequest(filename, resolvedPath);
|
|
76
|
+
debugStyles("NgtscProgram: external stylesheet ID mapped for resolveId", {
|
|
77
|
+
resourceName,
|
|
78
|
+
resolvedPath,
|
|
79
|
+
filename
|
|
80
|
+
});
|
|
81
|
+
return filename;
|
|
82
|
+
};
|
|
58
83
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return files;
|
|
67
|
-
};
|
|
84
|
+
function augmentProgramWithVersioning(program) {
|
|
85
|
+
const baseGetSourceFiles = program.getSourceFiles;
|
|
86
|
+
program.getSourceFiles = function(...parameters) {
|
|
87
|
+
const files = baseGetSourceFiles(...parameters);
|
|
88
|
+
for (const file of files) file.version ??= createHash("sha256").update(file.text).digest("hex");
|
|
89
|
+
return files;
|
|
90
|
+
};
|
|
68
91
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
cache.set(fileName, file);
|
|
78
|
-
}
|
|
79
|
-
return file;
|
|
80
|
-
};
|
|
92
|
+
function augmentHostWithCaching(host, cache) {
|
|
93
|
+
const baseGetSourceFile = host.getSourceFile;
|
|
94
|
+
host.getSourceFile = function(fileName, languageVersion, onError, shouldCreateNewSourceFile, ...parameters) {
|
|
95
|
+
if (!shouldCreateNewSourceFile && cache.has(fileName)) return cache.get(fileName);
|
|
96
|
+
const file = baseGetSourceFile.call(host, fileName, languageVersion, onError, true, ...parameters);
|
|
97
|
+
if (file) cache.set(fileName, file);
|
|
98
|
+
return file;
|
|
99
|
+
};
|
|
81
100
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
result.after = [...(first.after || []), ...(second.after || [])];
|
|
89
|
-
}
|
|
90
|
-
if (first.afterDeclarations || second.afterDeclarations) {
|
|
91
|
-
result.afterDeclarations = [
|
|
92
|
-
...(first.afterDeclarations || []),
|
|
93
|
-
...(second.afterDeclarations || []),
|
|
94
|
-
];
|
|
95
|
-
}
|
|
96
|
-
return result;
|
|
101
|
+
function mergeTransformers(first, second) {
|
|
102
|
+
const result = {};
|
|
103
|
+
if (first.before || second.before) result.before = [...first.before || [], ...second.before || []];
|
|
104
|
+
if (first.after || second.after) result.after = [...first.after || [], ...second.after || []];
|
|
105
|
+
if (first.afterDeclarations || second.afterDeclarations) result.afterDeclarations = [...first.afterDeclarations || [], ...second.afterDeclarations || []];
|
|
106
|
+
return result;
|
|
97
107
|
}
|
|
98
108
|
function hasStyleExtension(file) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
default:
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
109
|
+
switch (path.extname(file).toLowerCase()) {
|
|
110
|
+
case ".css":
|
|
111
|
+
case ".scss": return true;
|
|
112
|
+
default: return false;
|
|
113
|
+
}
|
|
107
114
|
}
|
|
115
|
+
//#endregion
|
|
116
|
+
export { augmentHostWithCaching, augmentHostWithResources, augmentProgramWithVersioning, mergeTransformers };
|
|
117
|
+
|
|
108
118
|
//# sourceMappingURL=host.js.map
|
package/src/lib/host.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host.js","sourceRoot":"","sources":["../../../../../packages/vite-plugin-angular/src/lib/host.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,MAAM,CAAC;AAIrC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,IAAI,MAAM,WAAW,CAAC;AAG7B,MAAM,UAAU,wBAAwB,CACtC,IAAqB,EACrB,SAI2B,EAC3B,OAMC;IAED,MAAM,YAAY,GAAG,IAAoB,CAAC;IAE1C,YAAY,CAAC,YAAY,GAAG,KAAK,WAAW,QAAgB;QAC1D,MAAM,QAAQ,GAAG,aAAa,CAAC,QAAQ,CAAC,CAAC;QAEzC,MAAM,OAAO,GAAI,IAAY,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;QAEjD,IAAI,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I,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CAAC;IACnE,CAAC;IAED,IAAI,KAAK,CAAC,iBAAiB,IAAI,MAAM,CAAC,iBAAiB,EAAE,CAAC;QACxD,MAAM,CAAC,iBAAiB,GAAG;YACzB,GAAG,CAAC,KAAK,CAAC,iBAAiB,IAAI,EAAE,CAAC;YAClC,GAAG,CAAC,MAAM,CAAC,iBAAiB,IAAI,EAAE,CAAC;SACpC,CAAC;IACJ,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,iBAAiB,CAAC,IAAY;IACrC,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC;IAEnD,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,MAAM,CAAC;QACZ,KAAK,OAAO;YACV,OAAO,IAAI,CAAC;QACd;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
1
|
+
{"version":3,"file":"host.js","names":[],"sources":["../../../src/lib/host.ts"],"sourcesContent":["import type { CompilerHost } from '@angular/compiler-cli';\nimport { normalizePath } from 'vite';\n\nimport * as ts from 'typescript';\n\nimport { createHash } from 'node:crypto';\nimport path from 'node:path';\nimport {\n normalizeStylesheetDependencies,\n type StylePreprocessor,\n} from './style-preprocessor.js';\nimport {\n AnalogStylesheetRegistry,\n preprocessStylesheetResult,\n registerStylesheetContent,\n} from './stylesheet-registry.js';\nimport { debugStyles } from './utils/debug.js';\nimport type { SourceFileCache } from './utils/source-file-cache.js';\nimport { isTailwindReferenceError } from './utils/tailwind-reference.js';\n\nexport function augmentHostWithResources(\n host: ts.CompilerHost,\n transform: (\n code: string,\n id: string,\n options?: { ssr?: boolean },\n ) => ReturnType<any> | null,\n options: {\n inlineStylesExtension: string;\n isProd?: boolean;\n stylesheetRegistry?: AnalogStylesheetRegistry;\n sourceFileCache?: SourceFileCache;\n stylePreprocessor?: StylePreprocessor;\n },\n): void {\n const resourceHost = host as CompilerHost;\n\n resourceHost.readResource = async function (fileName: string) {\n const filePath = normalizePath(fileName);\n\n const content = (this as any).readFile(filePath);\n\n if (content === undefined) {\n throw new Error('Unable to locate component resource: ' + fileName);\n }\n\n return content;\n };\n\n resourceHost.getModifiedResourceFiles = function () {\n return options?.sourceFileCache?.modifiedFiles;\n };\n\n resourceHost.transformResource = async function (data, context) {\n // Only style resources are supported currently\n if (context.type !== 'style') {\n return null;\n }\n\n const filename =\n context.resourceFile ??\n context.containingFile.replace(\n '.ts',\n `.${options?.inlineStylesExtension}`,\n );\n const preprocessed = preprocessStylesheetResult(\n data,\n filename,\n options.stylePreprocessor,\n {\n filename,\n containingFile: context.containingFile,\n resourceFile: context.resourceFile ?? undefined,\n className: context.className,\n order: context.order,\n inline: !context.resourceFile,\n },\n );\n\n // Externalized path: store preprocessed CSS for Vite's serve-time pipeline.\n // CSS must NOT be transformed here — the load hook returns it into\n // Vite's transform pipeline where PostCSS / Tailwind process it once.\n if (options.stylesheetRegistry) {\n const stylesheetId = registerStylesheetContent(\n options.stylesheetRegistry,\n {\n code: preprocessed.code,\n dependencies: normalizeStylesheetDependencies(\n preprocessed.dependencies,\n ),\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n containingFile: context.containingFile,\n className: context.className,\n order: context.order,\n inlineStylesExtension: options.inlineStylesExtension,\n resourceFile: context.resourceFile ?? undefined,\n },\n );\n debugStyles('NgtscProgram: stylesheet deferred to Vite pipeline', {\n stylesheetId,\n resourceFile: context.resourceFile ?? '(inline)',\n dependencies: preprocessed.dependencies,\n diagnostics: preprocessed.diagnostics,\n tags: preprocessed.tags,\n });\n return { content: stylesheetId };\n }\n\n // Non-externalized: CSS is returned directly to the Angular compiler\n // and never re-enters Vite's pipeline, so transform eagerly.\n debugStyles('NgtscProgram: stylesheet processed inline via transform', {\n filename,\n resourceFile: context.resourceFile ?? '(inline)',\n dataLength: preprocessed.code.length,\n });\n let stylesheetResult;\n\n try {\n stylesheetResult = await transform(\n preprocessed.code,\n `${filename}?direct`,\n );\n } catch (e) {\n if (isTailwindReferenceError(e)) {\n throw e;\n }\n debugStyles('NgtscProgram: stylesheet transform error', {\n filename,\n resourceFile: context.resourceFile ?? '(inline)',\n error: String(e),\n });\n }\n\n if (!stylesheetResult?.code) {\n return null;\n }\n\n return { content: stylesheetResult.code };\n };\n\n resourceHost.resourceNameToFileName = function (\n resourceName,\n containingFile,\n fallbackResolve,\n ) {\n const resolvedPath = normalizePath(\n fallbackResolve\n ? fallbackResolve(path.dirname(containingFile), resourceName)\n : path.join(path.dirname(containingFile), resourceName),\n );\n\n // All resource names that have template file extensions are assumed to be templates\n if (!options.stylesheetRegistry || !hasStyleExtension(resolvedPath)) {\n return resolvedPath;\n }\n\n // For external stylesheets, create a unique identifier and store the mapping\n const externalId = createHash('sha256').update(resolvedPath).digest('hex');\n const filename = externalId + path.extname(resolvedPath);\n\n options.stylesheetRegistry.registerExternalRequest(filename, resolvedPath);\n debugStyles('NgtscProgram: external stylesheet ID mapped for resolveId', {\n resourceName,\n resolvedPath,\n filename,\n });\n\n return filename;\n };\n}\n\nexport function augmentProgramWithVersioning(program: ts.Program): void {\n const baseGetSourceFiles = program.getSourceFiles;\n program.getSourceFiles = function (...parameters) {\n const files: readonly (ts.SourceFile & { version?: string })[] =\n baseGetSourceFiles(...parameters);\n\n for (const file of files) {\n file.version ??= createHash('sha256').update(file.text).digest('hex');\n }\n\n return files;\n };\n}\n\nexport function augmentHostWithCaching(\n host: ts.CompilerHost,\n cache: Map<string, ts.SourceFile>,\n): void {\n const baseGetSourceFile = host.getSourceFile;\n host.getSourceFile = function (\n fileName,\n languageVersion,\n onError,\n shouldCreateNewSourceFile,\n ...parameters\n ) {\n if (!shouldCreateNewSourceFile && cache.has(fileName)) {\n return cache.get(fileName);\n }\n\n const file = baseGetSourceFile.call(\n host,\n fileName,\n languageVersion,\n onError,\n true,\n ...parameters,\n );\n\n if (file) {\n cache.set(fileName, file);\n }\n\n return file;\n };\n}\n\nexport function mergeTransformers(\n first: ts.CustomTransformers,\n second: ts.CustomTransformers,\n): ts.CustomTransformers {\n const result: ts.CustomTransformers = {};\n\n if (first.before || second.before) {\n result.before = [...(first.before || []), ...(second.before || [])];\n }\n\n if (first.after || second.after) {\n result.after = [...(first.after || []), ...(second.after || [])];\n }\n\n if (first.afterDeclarations || second.afterDeclarations) {\n result.afterDeclarations = [\n ...(first.afterDeclarations || []),\n ...(second.afterDeclarations || []),\n ];\n }\n\n return result;\n}\n\nfunction hasStyleExtension(file: string): boolean {\n const extension = path.extname(file).toLowerCase();\n\n switch (extension) {\n case '.css':\n case '.scss':\n return true;\n default:\n return false;\n }\n}\n"],"mappings":";;;;;;;;AAoBA,SAAgB,yBACd,MACA,WAKA,SAOM;CACN,MAAM,eAAe;AAErB,cAAa,eAAe,eAAgB,UAAkB;EAC5D,MAAM,WAAW,cAAc,SAAS;EAExC,MAAM,UAAW,KAAa,SAAS,SAAS;AAEhD,MAAI,YAAY,KAAA,EACd,OAAM,IAAI,MAAM,0CAA0C,SAAS;AAGrE,SAAO;;AAGT,cAAa,2BAA2B,WAAY;AAClD,SAAO,SAAS,iBAAiB;;AAGnC,cAAa,oBAAoB,eAAgB,MAAM,SAAS;AAE9D,MAAI,QAAQ,SAAS,QACnB,QAAO;EAGT,MAAM,WACJ,QAAQ,gBACR,QAAQ,eAAe,QACrB,OACA,IAAI,SAAS,wBACd;EACH,MAAM,eAAe,2BACnB,MACA,UACA,QAAQ,mBACR;GACE;GACA,gBAAgB,QAAQ;GACxB,cAAc,QAAQ,gBAAgB,KAAA;GACtC,WAAW,QAAQ;GACnB,OAAO,QAAQ;GACf,QAAQ,CAAC,QAAQ;GAClB,CACF;AAKD,MAAI,QAAQ,oBAAoB;GAC9B,MAAM,eAAe,0BACnB,QAAQ,oBACR;IACE,MAAM,aAAa;IACnB,cAAc,gCACZ,aAAa,aACd;IACD,aAAa,aAAa;IAC1B,MAAM,a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AW;AAEnC,OAAK,MAAM,QAAQ,MACjB,MAAK,YAAY,WAAW,SAAS,CAAC,OAAO,KAAK,KAAK,CAAC,OAAO,MAAM;AAGvE,SAAO;;;AAIX,SAAgB,uBACd,MACA,OACM;CACN,MAAM,oBAAoB,KAAK;AAC/B,MAAK,gBAAgB,SACnB,UACA,iBACA,SACA,2BACA,GAAG,YACH;AACA,MAAI,CAAC,6BAA6B,MAAM,IAAI,SAAS,CACnD,QAAO,MAAM,IAAI,SAAS;EAG5B,MAAM,OAAO,kBAAkB,KAC7B,MACA,UACA,iBACA,SACA,MACA,GAAG,WACJ;AAED,MAAI,KACF,OAAM,IAAI,UAAU,KAAK;AAG3B,SAAO;;;AAIX,SAAgB,kBACd,OACA,QACuB;CACvB,MAAM,SAAgC,EAAE;AAExC,KAAI,MAAM,UAAU,OAAO,OACzB,QAAO,SAAS,CAAC,GAAI,MAAM,UAAU,EAAE,EAAG,GAAI,OAAO,UAAU,EAAE,CAAE;AAGrE,KAAI,MAAM,SAAS,OAAO,MACxB,QAAO,QAAQ,CAAC,GAAI,MAAM,SAAS,EAAE,EAAG,GAAI,OAAO,SAAS,EAAE,CAAE;AAGlE,KAAI,MAAM,qBAAqB,OAAO,kBACpC,QAAO,oBAAoB,CACzB,GAAI,MAAM,qBAAqB,EAAE,EACjC,GAAI,OAAO,qBAAqB,EAAE,CACnC;AAGH,QAAO;;AAGT,SAAS,kBAAkB,MAAuB;AAGhD,SAFkB,KAAK,QAAQ,KAAK,CAAC,aAAa,EAElD;EACE,KAAK;EACL,KAAK,QACH,QAAO;EACT,QACE,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Plugin } from
|
|
2
|
-
import { EmitFileResult } from
|
|
3
|
-
export declare function liveReloadPlugin({ classNames, fileEmitter
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
|
+
import { EmitFileResult } from "./models.js";
|
|
3
|
+
export declare function liveReloadPlugin({ classNames, fileEmitter }: {
|
|
4
|
+
classNames: Map<string, string>;
|
|
5
|
+
fileEmitter: (file: string) => EmitFileResult | undefined;
|
|
6
6
|
}): Plugin;
|
|
@@ -1,64 +1,63 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
return;
|
|
61
|
-
},
|
|
62
|
-
};
|
|
1
|
+
import { debugHmr } from "./utils/debug.js";
|
|
2
|
+
import { resolve } from "node:path";
|
|
3
|
+
import { normalizePath } from "vite";
|
|
4
|
+
//#region packages/vite-plugin-angular/src/lib/live-reload-plugin.ts
|
|
5
|
+
var ANGULAR_COMPONENT_PREFIX = "/@ng/component";
|
|
6
|
+
var FILE_PREFIX = "file:";
|
|
7
|
+
function liveReloadPlugin({ classNames, fileEmitter }) {
|
|
8
|
+
return {
|
|
9
|
+
name: "analogjs-live-reload-plugin",
|
|
10
|
+
apply: "serve",
|
|
11
|
+
configureServer(server) {
|
|
12
|
+
if (server.config.server.hmr === false) {
|
|
13
|
+
debugHmr("middleware disabled: vite server.hmr is false");
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const angularComponentMiddleware = async (req, res, next) => {
|
|
17
|
+
if (req.url === void 0 || res.writableEnded) return;
|
|
18
|
+
if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {
|
|
19
|
+
next();
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const componentId = new URL(req.url, "http://localhost").searchParams.get("c");
|
|
23
|
+
if (!componentId) {
|
|
24
|
+
res.statusCode = 400;
|
|
25
|
+
res.end();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const [fileId] = decodeURIComponent(componentId).split("@");
|
|
29
|
+
const resolvedId = normalizePath(resolve(process.cwd(), fileId));
|
|
30
|
+
if (!(!!server.moduleGraph.getModuleById(resolvedId)?.lastInvalidationTimestamp && classNames.get(resolvedId))) {
|
|
31
|
+
debugHmr("middleware: skipped (not invalidated)", { resolvedId });
|
|
32
|
+
res.setHeader("Content-Type", "text/javascript");
|
|
33
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
34
|
+
res.end("");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
const result = fileEmitter(resolvedId);
|
|
38
|
+
debugHmr("middleware: served component update", {
|
|
39
|
+
resolvedId,
|
|
40
|
+
hasCode: !!result?.hmrUpdateCode
|
|
41
|
+
});
|
|
42
|
+
res.setHeader("Content-Type", "text/javascript");
|
|
43
|
+
res.setHeader("Cache-Control", "no-cache");
|
|
44
|
+
res.end(`${result?.hmrUpdateCode || ""}`);
|
|
45
|
+
};
|
|
46
|
+
server.middlewares.use(angularComponentMiddleware);
|
|
47
|
+
},
|
|
48
|
+
resolveId(id, _importer, options) {
|
|
49
|
+
if (options?.ssr && id.startsWith(FILE_PREFIX) && id.includes(ANGULAR_COMPONENT_PREFIX)) return `\0${id}`;
|
|
50
|
+
},
|
|
51
|
+
load(id, options) {
|
|
52
|
+
if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {
|
|
53
|
+
const componentId = new URL(id.slice(1), "http://localhost").searchParams.get("c");
|
|
54
|
+
if (!componentId) return;
|
|
55
|
+
return fileEmitter(normalizePath(resolve(process.cwd(), decodeURIComponent(componentId).split("@")[0])))?.hmrUpdateCode || "";
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
63
59
|
}
|
|
60
|
+
//#endregion
|
|
61
|
+
export { liveReloadPlugin };
|
|
62
|
+
|
|
64
63
|
//# sourceMappingURL=live-reload-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"live-reload-plugin.js","
|
|
1
|
+
{"version":3,"file":"live-reload-plugin.js","names":[],"sources":["../../../src/lib/live-reload-plugin.ts"],"sourcesContent":["import { resolve } from 'node:path';\nimport { ServerResponse } from 'node:http';\nimport { Connect, normalizePath, Plugin, ViteDevServer } from 'vite';\n\nimport { EmitFileResult } from './models.js';\nimport { debugHmr } from './utils/debug.js';\n\nconst ANGULAR_COMPONENT_PREFIX = '/@ng/component';\nconst FILE_PREFIX = 'file:';\n\nexport function liveReloadPlugin({\n classNames,\n fileEmitter,\n}: {\n classNames: Map<string, string>;\n fileEmitter: (file: string) => EmitFileResult | undefined;\n}): Plugin {\n return {\n name: 'analogjs-live-reload-plugin',\n apply: 'serve',\n configureServer(server: ViteDevServer) {\n if (server.config.server.hmr === false) {\n debugHmr('middleware disabled: vite server.hmr is false');\n return;\n }\n\n const angularComponentMiddleware: Connect.HandleFunction = async (\n req: Connect.IncomingMessage,\n res: ServerResponse<Connect.IncomingMessage>,\n next: Connect.NextFunction,\n ) => {\n if (req.url === undefined || res.writableEnded) {\n return;\n }\n\n if (!req.url.includes(ANGULAR_COMPONENT_PREFIX)) {\n next();\n\n return;\n }\n\n const requestUrl = new URL(req.url, 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n res.statusCode = 400;\n res.end();\n\n return;\n }\n\n const [fileId] = decodeURIComponent(componentId).split('@');\n const resolvedId = normalizePath(resolve(process.cwd(), fileId));\n const invalidated =\n !!server.moduleGraph.getModuleById(resolvedId)\n ?.lastInvalidationTimestamp && classNames.get(resolvedId);\n\n // don't send an HMR update until the file has been invalidated\n if (!invalidated) {\n debugHmr('middleware: skipped (not invalidated)', { resolvedId });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end('');\n return;\n }\n\n const result = fileEmitter(resolvedId);\n debugHmr('middleware: served component update', {\n resolvedId,\n hasCode: !!result?.hmrUpdateCode,\n });\n res.setHeader('Content-Type', 'text/javascript');\n res.setHeader('Cache-Control', 'no-cache');\n res.end(`${result?.hmrUpdateCode || ''}`);\n };\n\n server.middlewares.use(angularComponentMiddleware);\n },\n resolveId(id, _importer, options) {\n if (\n options?.ssr &&\n id.startsWith(FILE_PREFIX) &&\n id.includes(ANGULAR_COMPONENT_PREFIX)\n ) {\n return `\\0${id}`;\n }\n\n return undefined;\n },\n load(id, options) {\n if (options?.ssr && id.includes(ANGULAR_COMPONENT_PREFIX)) {\n const requestUrl = new URL(id.slice(1), 'http://localhost');\n const componentId = requestUrl.searchParams.get('c');\n\n if (!componentId) {\n return;\n }\n\n const result = fileEmitter(\n normalizePath(\n resolve(\n process.cwd(),\n decodeURIComponent(componentId).split('@')[0],\n ),\n ),\n );\n\n return result?.hmrUpdateCode || '';\n }\n\n return;\n },\n };\n}\n"],"mappings":";;;;AAOA,IAAM,2BAA2B;AACjC,IAAM,cAAc;AAEpB,SAAgB,iBAAiB,EAC/B,YACA,eAIS;AACT,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,QAAuB;AACrC,OAAI,OAAO,OAAO,OAAO,QAAQ,OAAO;AACtC,aAAS,gDAAgD;AACzD;;GAGF,MAAM,6BAAqD,OACzD,KACA,KACA,SACG;AACH,QAAI,IAAI,QAAQ,KAAA,KAAa,I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AEc,iBAAiB;;;EAKrC"}
|
package/src/lib/models.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type ts from
|
|
1
|
+
import type ts from "typescript";
|
|
2
2
|
export interface EmitFileResult {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
content?: string;
|
|
4
|
+
map?: string;
|
|
5
|
+
dependencies: readonly string[];
|
|
6
|
+
hash?: Uint8Array;
|
|
7
|
+
errors?: (string | ts.DiagnosticMessageChain)[];
|
|
8
|
+
warnings?: (string | ts.DiagnosticMessageChain)[];
|
|
9
|
+
hmrUpdateCode?: string | null;
|
|
10
|
+
hmrEligible?: boolean | null;
|
|
11
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
2
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
* Ignores anything in the .nx folder from triggering HMR
|
|
4
|
+
*
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
7
|
export declare function nxFolderPlugin(): Plugin;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { normalizePath } from
|
|
1
|
+
import { normalizePath } from "vite";
|
|
2
|
+
//#region packages/vite-plugin-angular/src/lib/nx-folder-plugin.ts
|
|
2
3
|
/**
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
};
|
|
4
|
+
* Ignores anything in the .nx folder from triggering HMR
|
|
5
|
+
*
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
function nxFolderPlugin() {
|
|
9
|
+
return {
|
|
10
|
+
name: "analogjs-nx-folder-plugin",
|
|
11
|
+
apply: "serve",
|
|
12
|
+
handleHotUpdate(ctx) {
|
|
13
|
+
if (ctx.file.includes(normalizePath("/.nx/"))) return [];
|
|
14
|
+
return ctx.modules;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
18
17
|
}
|
|
18
|
+
//#endregion
|
|
19
|
+
export { nxFolderPlugin };
|
|
20
|
+
|
|
19
21
|
//# sourceMappingURL=nx-folder-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nx-folder-plugin.js","
|
|
1
|
+
{"version":3,"file":"nx-folder-plugin.js","names":[],"sources":["../../../src/lib/nx-folder-plugin.ts"],"sourcesContent":["import { normalizePath, Plugin } from 'vite';\n\n/**\n * Ignores anything in the .nx folder from triggering HMR\n *\n * @returns\n */\nexport function nxFolderPlugin(): Plugin {\n return {\n name: 'analogjs-nx-folder-plugin',\n apply: 'serve',\n handleHotUpdate(ctx) {\n if (ctx.file.includes(normalizePath('/.nx/'))) {\n return [];\n }\n\n return ctx.modules;\n },\n };\n}\n"],"mappings":";;;;;;;AAOA,SAAgB,iBAAyB;AACvC,QAAO;EACL,MAAM;EACN,OAAO;EACP,gBAAgB,KAAK;AACnB,OAAI,IAAI,KAAK,SAAS,cAAc,QAAQ,CAAC,CAC3C,QAAO,EAAE;AAGX,UAAO,IAAI;;EAEd"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Plugin } from
|
|
1
|
+
import { Plugin } from "vite";
|
|
2
2
|
export declare function replaceFiles(replacements: FileReplacement[], workspaceRoot: string): Plugin | false;
|
|
3
3
|
export type FileReplacement = FileReplacementWith | FileReplacementSSR;
|
|
4
4
|
export interface FileReplacementBase {
|
|
5
|
-
|
|
5
|
+
replace: string;
|
|
6
6
|
}
|
|
7
7
|
export interface FileReplacementWith extends FileReplacementBase {
|
|
8
|
-
|
|
8
|
+
with: string;
|
|
9
9
|
}
|
|
10
10
|
export interface FileReplacementSSR extends FileReplacementBase {
|
|
11
|
-
|
|
11
|
+
ssr: string;
|
|
12
12
|
}
|