@nativescript/vite 0.0.1 → 1.0.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/LICENSE +19 -0
- package/README.md +81 -0
- package/{dist/configuration → configuration}/angular.d.ts +1 -1
- package/configuration/angular.js +371 -0
- package/configuration/angular.js.map +1 -0
- package/configuration/base.d.ts +5 -0
- package/configuration/base.js +491 -0
- package/configuration/base.js.map +1 -0
- package/configuration/javascript.d.ts +4 -0
- package/configuration/javascript.js +152 -0
- package/configuration/javascript.js.map +1 -0
- package/{dist/configuration → configuration}/react.d.ts +1 -1
- package/{dist/configuration → configuration}/react.js +18 -17
- package/configuration/react.js.map +1 -0
- package/{dist/configuration → configuration}/solid.d.ts +1 -1
- package/{dist/configuration → configuration}/solid.js +17 -16
- package/configuration/solid.js.map +1 -0
- package/configuration/typescript.d.ts +4 -0
- package/configuration/typescript.js +176 -0
- package/configuration/typescript.js.map +1 -0
- package/{dist/configuration → configuration}/vue.d.ts +1 -1
- package/configuration/vue.js +163 -0
- package/configuration/vue.js.map +1 -0
- package/helpers/angular/angular-linker.d.ts +13 -0
- package/helpers/angular/angular-linker.js +189 -0
- package/helpers/angular/angular-linker.js.map +1 -0
- package/helpers/angular/shared-linker.d.ts +4 -0
- package/helpers/angular/shared-linker.js +39 -0
- package/helpers/angular/shared-linker.js.map +1 -0
- package/helpers/angular/util.d.ts +1 -0
- package/helpers/angular/util.js +67 -0
- package/helpers/angular/util.js.map +1 -0
- package/helpers/cli-flags.d.ts +1 -0
- package/helpers/cli-flags.js +15 -0
- package/helpers/cli-flags.js.map +1 -0
- package/{dist/helpers → helpers}/commonjs-plugins.js +14 -13
- package/helpers/commonjs-plugins.js.map +1 -0
- package/{dist/helpers → helpers}/config-as-json.d.ts +1 -1
- package/{dist/helpers → helpers}/config-as-json.js +7 -6
- package/helpers/config-as-json.js.map +1 -0
- package/helpers/css-platform-plugin.d.ts +10 -0
- package/helpers/css-platform-plugin.js +76 -0
- package/helpers/css-platform-plugin.js.map +1 -0
- package/helpers/css-tree.js +22 -0
- package/helpers/css-tree.js.map +1 -0
- package/{dist/helpers → helpers}/dynamic-import-plugin.js +8 -7
- package/helpers/dynamic-import-plugin.js.map +1 -0
- package/helpers/esbuild-platform-resolver.d.ts +14 -0
- package/helpers/esbuild-platform-resolver.js +93 -0
- package/helpers/esbuild-platform-resolver.js.map +1 -0
- package/helpers/external-configs.d.ts +6 -0
- package/helpers/external-configs.js +34 -0
- package/helpers/external-configs.js.map +1 -0
- package/{dist/helpers → helpers}/flavor.d.ts +1 -0
- package/helpers/flavor.js +51 -0
- package/helpers/flavor.js.map +1 -0
- package/helpers/global-defines.d.ts +25 -0
- package/helpers/global-defines.js +29 -0
- package/helpers/global-defines.js.map +1 -0
- package/helpers/init.d.ts +1 -0
- package/helpers/init.js +119 -0
- package/helpers/init.js.map +1 -0
- package/helpers/logging.d.ts +13 -0
- package/helpers/logging.js +115 -0
- package/helpers/logging.js.map +1 -0
- package/helpers/main-entry.d.ts +10 -0
- package/helpers/main-entry.js +223 -0
- package/helpers/main-entry.js.map +1 -0
- package/{dist/helpers → helpers}/module-resolution.js +4 -3
- package/helpers/module-resolution.js.map +1 -0
- package/helpers/module-runner-patch.d.ts +3 -0
- package/helpers/module-runner-patch.js +63 -0
- package/helpers/module-runner-patch.js.map +1 -0
- package/helpers/nativeclass-transform.d.ts +7 -0
- package/helpers/nativeclass-transform.js +158 -0
- package/helpers/nativeclass-transform.js.map +1 -0
- package/helpers/nativeclass-transformer-plugin.d.ts +5 -0
- package/helpers/nativeclass-transformer-plugin.js +23 -0
- package/helpers/nativeclass-transformer-plugin.js.map +1 -0
- package/{dist/helpers → helpers}/nativescript-package-resolver.js +18 -17
- package/helpers/nativescript-package-resolver.js.map +1 -0
- package/helpers/ns-cli-plugins.d.ts +14 -0
- package/helpers/ns-cli-plugins.js +165 -0
- package/helpers/ns-cli-plugins.js.map +1 -0
- package/helpers/package-platform-aliases.d.ts +10 -0
- package/{dist/helpers → helpers}/package-platform-aliases.js +19 -23
- package/helpers/package-platform-aliases.js.map +1 -0
- package/helpers/postcss-platform-config.d.ts +13 -0
- package/helpers/postcss-platform-config.js +97 -0
- package/helpers/postcss-platform-config.js.map +1 -0
- package/helpers/prelink-angular.d.ts +2 -0
- package/helpers/prelink-angular.js +117 -0
- package/helpers/prelink-angular.js.map +1 -0
- package/helpers/preserve-imports.d.ts +2 -0
- package/helpers/preserve-imports.js +38 -0
- package/helpers/preserve-imports.js.map +1 -0
- package/{dist/helpers → helpers}/project.js +2 -4
- package/helpers/project.js.map +1 -0
- package/helpers/resolver.d.ts +4 -0
- package/{dist/helpers → helpers}/resolver.js +7 -6
- package/helpers/resolver.js.map +1 -0
- package/helpers/theme-core-plugins.d.ts +14 -0
- package/helpers/theme-core-plugins.js +121 -0
- package/helpers/theme-core-plugins.js.map +1 -0
- package/helpers/ts-config-paths.d.ts +10 -0
- package/{dist/helpers → helpers}/ts-config-paths.js +73 -72
- package/helpers/ts-config-paths.js.map +1 -0
- package/{dist/helpers → helpers}/utils.d.ts +10 -0
- package/helpers/utils.js +143 -0
- package/helpers/utils.js.map +1 -0
- package/{dist/helpers → helpers}/workers.js +15 -16
- package/helpers/workers.js.map +1 -0
- package/hmr/client/css-handler.d.ts +4 -0
- package/hmr/client/css-handler.js +78 -0
- package/hmr/client/css-handler.js.map +1 -0
- package/hmr/client/index.d.ts +13 -0
- package/hmr/client/index.js +1723 -0
- package/hmr/client/index.js.map +1 -0
- package/hmr/client/utils.d.ts +38 -0
- package/hmr/client/utils.js +426 -0
- package/hmr/client/utils.js.map +1 -0
- package/hmr/entry-runtime.d.ts +8 -0
- package/hmr/entry-runtime.js +135 -0
- package/hmr/entry-runtime.js.map +1 -0
- package/hmr/frameworks/angular/client/index.d.ts +8 -0
- package/hmr/frameworks/angular/client/index.js +59 -0
- package/hmr/frameworks/angular/client/index.js.map +1 -0
- package/hmr/frameworks/angular/server/linker.d.ts +1 -0
- package/hmr/frameworks/angular/server/linker.js +101 -0
- package/hmr/frameworks/angular/server/linker.js.map +1 -0
- package/hmr/frameworks/angular/server/strategy.d.ts +2 -0
- package/hmr/frameworks/angular/server/strategy.js +187 -0
- package/hmr/frameworks/angular/server/strategy.js.map +1 -0
- package/hmr/frameworks/solid/server/strategy.d.ts +2 -0
- package/hmr/frameworks/solid/server/strategy.js +56 -0
- package/hmr/frameworks/solid/server/strategy.js.map +1 -0
- package/hmr/frameworks/typescript/server/strategy.d.ts +2 -0
- package/hmr/frameworks/typescript/server/strategy.js +125 -0
- package/hmr/frameworks/typescript/server/strategy.js.map +1 -0
- package/hmr/frameworks/vue/client/index.d.ts +22 -0
- package/hmr/frameworks/vue/client/index.js +1541 -0
- package/hmr/frameworks/vue/client/index.js.map +1 -0
- package/hmr/frameworks/vue/server/compiler.d.ts +11 -0
- package/hmr/frameworks/vue/server/compiler.js +26 -0
- package/hmr/frameworks/vue/server/compiler.js.map +1 -0
- package/hmr/frameworks/vue/server/sfc-transforms.d.ts +14 -0
- package/hmr/frameworks/vue/server/sfc-transforms.js +282 -0
- package/hmr/frameworks/vue/server/sfc-transforms.js.map +1 -0
- package/hmr/frameworks/vue/server/strategy.d.ts +2 -0
- package/hmr/frameworks/vue/server/strategy.js +272 -0
- package/hmr/frameworks/vue/server/strategy.js.map +1 -0
- package/hmr/helpers/ast-extract.d.ts +6 -0
- package/hmr/helpers/ast-extract.js +72 -0
- package/hmr/helpers/ast-extract.js.map +1 -0
- package/hmr/helpers/ast-normalizer.d.ts +7 -0
- package/hmr/helpers/ast-normalizer.js +772 -0
- package/hmr/helpers/ast-normalizer.js.map +1 -0
- package/hmr/helpers/babel.d.ts +3 -0
- package/hmr/helpers/babel.js +17 -0
- package/hmr/helpers/babel.js.map +1 -0
- package/hmr/helpers/sanitize.d.ts +6 -0
- package/hmr/helpers/sanitize.js +55 -0
- package/hmr/helpers/sanitize.js.map +1 -0
- package/hmr/helpers/vendor-rewrite.d.ts +1 -0
- package/hmr/helpers/vendor-rewrite.js +35 -0
- package/hmr/helpers/vendor-rewrite.js.map +1 -0
- package/hmr/server/compiler.d.ts +2 -0
- package/hmr/server/compiler.js +75 -0
- package/hmr/server/compiler.js.map +1 -0
- package/hmr/server/constants.d.ts +14 -0
- package/hmr/server/constants.js +23 -0
- package/hmr/server/constants.js.map +1 -0
- package/hmr/server/core-sanitize.d.ts +32 -0
- package/hmr/server/core-sanitize.js +134 -0
- package/hmr/server/core-sanitize.js.map +1 -0
- package/hmr/server/framework-strategy.d.ts +68 -0
- package/hmr/server/framework-strategy.js +2 -0
- package/hmr/server/framework-strategy.js.map +1 -0
- package/hmr/server/index.d.ts +5 -0
- package/hmr/server/index.js +23 -0
- package/hmr/server/index.js.map +1 -0
- package/hmr/server/vite-plugin.d.ts +5 -0
- package/hmr/server/vite-plugin.js +44 -0
- package/hmr/server/vite-plugin.js.map +1 -0
- package/hmr/server/websocket.d.ts +21 -0
- package/hmr/server/websocket.js +5619 -0
- package/hmr/server/websocket.js.map +1 -0
- package/hmr/shared/runtime/http-only-boot.d.ts +1 -0
- package/hmr/shared/runtime/http-only-boot.js +107 -0
- package/hmr/shared/runtime/http-only-boot.js.map +1 -0
- package/hmr/shared/runtime/root-placeholder.d.ts +1 -0
- package/hmr/shared/runtime/root-placeholder.js +142 -0
- package/hmr/shared/runtime/root-placeholder.js.map +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.d.ts +1 -0
- package/hmr/shared/runtime/vendor-bootstrap.js +134 -0
- package/hmr/shared/runtime/vendor-bootstrap.js.map +1 -0
- package/hmr/shared/vendor/manifest-loader.d.ts +9 -0
- package/hmr/shared/vendor/manifest-loader.js +38 -0
- package/hmr/shared/vendor/manifest-loader.js.map +1 -0
- package/hmr/shared/vendor/manifest.d.ts +35 -0
- package/hmr/shared/vendor/manifest.js +811 -0
- package/hmr/shared/vendor/manifest.js.map +1 -0
- package/hmr/shared/vendor/registry.d.ts +9 -0
- package/hmr/shared/vendor/registry.js +62 -0
- package/hmr/shared/vendor/registry.js.map +1 -0
- package/hmr/vendor-bootstrap.d.ts +3 -0
- package/hmr/vendor-bootstrap.js +32 -0
- package/hmr/vendor-bootstrap.js.map +1 -0
- package/{dist/index.d.ts → index.d.ts} +2 -0
- package/index.js +19 -0
- package/index.js.map +1 -0
- package/package.json +42 -30
- package/{dist/polyfills → polyfills}/mdn-data-at-rules.js +1 -0
- package/polyfills/mdn-data-at-rules.js.map +1 -0
- package/{dist/polyfills → polyfills}/mdn-data-properties.js +1 -0
- package/polyfills/mdn-data-properties.js.map +1 -0
- package/{dist/polyfills → polyfills}/mdn-data-syntaxes.js +1 -0
- package/polyfills/mdn-data-syntaxes.js.map +1 -0
- package/{dist/polyfills → polyfills}/module.js +1 -0
- package/polyfills/module.js.map +1 -0
- package/runtime/core-aliases-early.d.ts +1 -0
- package/runtime/core-aliases-early.js +334 -0
- package/runtime/core-aliases-early.js.map +1 -0
- package/shims/angular-animations-stub.d.ts +68 -0
- package/shims/angular-animations-stub.js +140 -0
- package/shims/angular-animations-stub.js.map +1 -0
- package/shims/node-module.d.ts +5 -0
- package/shims/node-module.js +13 -0
- package/shims/node-module.js.map +1 -0
- package/{dist/shims → shims}/react-reconciler-constants.js +2 -1
- package/shims/react-reconciler-constants.js.map +1 -0
- package/{dist/shims → shims}/react-reconciler.js +1 -0
- package/shims/react-reconciler.js.map +1 -0
- package/{dist/shims → shims}/set-value.js +5 -1
- package/shims/set-value.js.map +1 -0
- package/transformers/NativeClass/index.d.ts +2 -0
- package/transformers/NativeClass/index.js +222 -0
- package/transformers/NativeClass/index.js.map +1 -0
- package/dist/configuration/angular.js +0 -30
- package/dist/configuration/base.d.ts +0 -13
- package/dist/configuration/base.js +0 -228
- package/dist/configuration/old-without-merge-base.d.ts +0 -13
- package/dist/configuration/old-without-merge-base.js +0 -249
- package/dist/configuration/vue.js +0 -45
- package/dist/helpers/css-tree.js +0 -21
- package/dist/helpers/flavor.js +0 -40
- package/dist/helpers/global-defines.d.ts +0 -14
- package/dist/helpers/global-defines.js +0 -18
- package/dist/helpers/main-entry.d.ts +0 -5
- package/dist/helpers/main-entry.js +0 -75
- package/dist/helpers/ns-cli-plugins.d.ts +0 -17
- package/dist/helpers/ns-cli-plugins.js +0 -128
- package/dist/helpers/package-platform-aliases.d.ts +0 -4
- package/dist/helpers/resolver.d.ts +0 -4
- package/dist/helpers/ts-config-paths.d.ts +0 -4
- package/dist/helpers/utils.js +0 -94
- package/dist/hmr/hmr-angular.d.ts +0 -1
- package/dist/hmr/hmr-angular.js +0 -34
- package/dist/hmr/hmr-bridge.d.ts +0 -18
- package/dist/hmr/hmr-bridge.js +0 -154
- package/dist/hmr/hmr-client.d.ts +0 -5
- package/dist/hmr/hmr-client.js +0 -93
- package/dist/hmr/hmr-server.d.ts +0 -20
- package/dist/hmr/hmr-server.js +0 -179
- package/dist/index.js +0 -5
- package/dist/transformers/NativeClass/index.d.ts +0 -5
- package/dist/transformers/NativeClass/index.js +0 -46
- /package/{dist/helpers → helpers}/commonjs-plugins.d.ts +0 -0
- /package/{dist/helpers → helpers}/css-tree.d.ts +0 -0
- /package/{dist/helpers → helpers}/dynamic-import-plugin.d.ts +0 -0
- /package/{dist/helpers → helpers}/module-resolution.d.ts +0 -0
- /package/{dist/helpers → helpers}/nativescript-package-resolver.d.ts +0 -0
- /package/{dist/helpers → helpers}/project.d.ts +0 -0
- /package/{dist/helpers → helpers}/workers.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-at-rules.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-properties.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/mdn-data-syntaxes.d.ts +0 -0
- /package/{dist/polyfills → polyfills}/module.d.ts +0 -0
- /package/{dist/shims → shims}/react-reconciler-constants.d.ts +0 -0
- /package/{dist/shims → shims}/react-reconciler.d.ts +0 -0
- /package/{dist/shims → shims}/set-value.d.ts +0 -0
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
// NativeClass transformer for Vite
|
|
3
|
+
// Detect both @NativeClass and /*__NativeClass__*/ markers and downlevel ONLY the marked class
|
|
4
|
+
// while leaving everything else at the project’s target.
|
|
5
|
+
export default function (ctx) {
|
|
6
|
+
const factory = ctx.factory ?? ts.factory;
|
|
7
|
+
return (sourceFile) => {
|
|
8
|
+
if (sourceFile.isDeclarationFile)
|
|
9
|
+
return sourceFile;
|
|
10
|
+
let mutated = false;
|
|
11
|
+
function getIdentifierText(node) {
|
|
12
|
+
if (!node)
|
|
13
|
+
return undefined;
|
|
14
|
+
if (ts.isIdentifier(node))
|
|
15
|
+
return node.text;
|
|
16
|
+
if (ts.isDecorator(node))
|
|
17
|
+
return getIdentifierText(node.expression);
|
|
18
|
+
if (ts.isCallExpression(node))
|
|
19
|
+
return getIdentifierText(node.expression);
|
|
20
|
+
if (ts.isPropertyAccessExpression(node))
|
|
21
|
+
return node.name.text;
|
|
22
|
+
if (ts.isParenthesizedExpression(node))
|
|
23
|
+
return getIdentifierText(node.expression);
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
function hasNativeClassDecorator(node) {
|
|
27
|
+
// AST-level
|
|
28
|
+
const decorators = ('canHaveDecorators' in ts && ts.canHaveDecorators(node) ? ts.getDecorators(node) : node.decorators);
|
|
29
|
+
if (decorators?.some((d) => getIdentifierText(d) === 'NativeClass'))
|
|
30
|
+
return true;
|
|
31
|
+
// Leading trivia raw-text and marker detection
|
|
32
|
+
const sf = node.getSourceFile?.() ?? sourceFile;
|
|
33
|
+
const fullStart = node.getFullStart ? node.getFullStart() : node.pos;
|
|
34
|
+
const header = sf.text.slice(fullStart, node.getStart(sf));
|
|
35
|
+
if (/\/\*__NativeClass__\*\//.test(header))
|
|
36
|
+
return true;
|
|
37
|
+
if (/^\s*@NativeClass\b/m.test(header))
|
|
38
|
+
return true;
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
function emitDownleveledClass(node) {
|
|
42
|
+
const sf = node.getSourceFile?.() ?? sourceFile;
|
|
43
|
+
const fullStart = node.getFullStart ? node.getFullStart() : node.pos;
|
|
44
|
+
const nodeText = sf.text.slice(fullStart, node.end);
|
|
45
|
+
// Remove marker/decorator but preserve surrounding newline so next 'class' stays on its own line
|
|
46
|
+
let stripped = nodeText.replace(/@NativeClass(?:\([\s\S]*?\))?/m, '').replace(/\/\*__NativeClass__\*\//m, '');
|
|
47
|
+
// Provide a .ts filename to help transpileModule parse TS types consistently
|
|
48
|
+
const transpileResult = ts.transpileModule(stripped, {
|
|
49
|
+
compilerOptions: {
|
|
50
|
+
module: ts.ModuleKind.ESNext,
|
|
51
|
+
target: ts.ScriptTarget.ES5,
|
|
52
|
+
noEmitHelpers: true,
|
|
53
|
+
experimentalDecorators: true,
|
|
54
|
+
emitDecoratorMetadata: true,
|
|
55
|
+
useDefineForClassFields: false,
|
|
56
|
+
},
|
|
57
|
+
fileName: sf.fileName.endsWith('.ts') ? sf.fileName : `${sf.fileName}.ts`,
|
|
58
|
+
reportDiagnostics: !!process.env.NATIVECLASS_DEBUG,
|
|
59
|
+
});
|
|
60
|
+
if (process.env.NATIVECLASS_DEBUG && transpileResult.diagnostics?.length) {
|
|
61
|
+
// Emit only first diagnostic for brevity
|
|
62
|
+
const first = transpileResult.diagnostics[0];
|
|
63
|
+
console.warn('[NativeClass:vite] diagnostic', first.messageText);
|
|
64
|
+
}
|
|
65
|
+
const downleveled = transpileResult.outputText;
|
|
66
|
+
const helperSource = ts.createSourceFile(`${node.getSourceFile()?.fileName ?? 'NativeClass.ts'}.helper.js`, downleveled, ts.ScriptTarget.ES5, true, ts.ScriptKind.JS);
|
|
67
|
+
// Visitor to set enumerable: true inside Object.defineProperty descriptor objects safely (no regex)
|
|
68
|
+
const makeEnumerableVisitor = (n) => {
|
|
69
|
+
return ts.visitEachChild(n, (child) => {
|
|
70
|
+
if (ts.isCallExpression(child)) {
|
|
71
|
+
const exp = child.expression;
|
|
72
|
+
const isDefineProp = ts.isPropertyAccessExpression(exp) ? exp.name.text === 'defineProperty' && ts.isIdentifier(exp.expression) && exp.expression.text === 'Object' : ts.isIdentifier(exp) && exp.text === 'Object'; // fallback, though TS emits property access
|
|
73
|
+
if (isDefineProp && child.arguments.length >= 3 && ts.isObjectLiteralExpression(child.arguments[2])) {
|
|
74
|
+
const obj = child.arguments[2];
|
|
75
|
+
const newProps = obj.properties.map((p) => {
|
|
76
|
+
if (ts.isPropertyAssignment(p)) {
|
|
77
|
+
const name = p.name;
|
|
78
|
+
const isEnumerable = (ts.isIdentifier(name) && name.text === 'enumerable') || (ts.isStringLiteral(name) && name.text === 'enumerable');
|
|
79
|
+
if (isEnumerable) {
|
|
80
|
+
return factory.updatePropertyAssignment(p, p.name, factory.createTrue());
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return p;
|
|
84
|
+
});
|
|
85
|
+
const newObj = factory.updateObjectLiteralExpression(obj, newProps);
|
|
86
|
+
const newArgs = [...child.arguments.slice(0, 2), newObj, ...child.arguments.slice(3)];
|
|
87
|
+
return factory.updateCallExpression(child, child.expression, child.typeArguments, newArgs);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return makeEnumerableVisitor(child);
|
|
91
|
+
}, ctx);
|
|
92
|
+
};
|
|
93
|
+
const transformedStatements = [];
|
|
94
|
+
for (const stmt of helperSource.statements) {
|
|
95
|
+
if (stmt.kind === ts.SyntaxKind.EndOfFileToken)
|
|
96
|
+
continue;
|
|
97
|
+
const updated = ts.visitNode(stmt, makeEnumerableVisitor);
|
|
98
|
+
transformedStatements.push(updated);
|
|
99
|
+
}
|
|
100
|
+
const out = transformedStatements;
|
|
101
|
+
return out;
|
|
102
|
+
}
|
|
103
|
+
function removeNativeClassImport(node) {
|
|
104
|
+
const clause = node.importClause;
|
|
105
|
+
if (!clause || !clause.namedBindings || !ts.isNamedImports(clause.namedBindings))
|
|
106
|
+
return node;
|
|
107
|
+
const remain = clause.namedBindings.elements.filter((el) => (el.propertyName ?? el.name).text !== 'NativeClass');
|
|
108
|
+
if (remain.length === clause.namedBindings.elements.length)
|
|
109
|
+
return node;
|
|
110
|
+
if (remain.length === 0 && !clause.name && !clause.isTypeOnly && !clause.phaseModifier)
|
|
111
|
+
return undefined;
|
|
112
|
+
const updatedNamed = remain.length ? factory.updateNamedImports(clause.namedBindings, remain) : undefined;
|
|
113
|
+
const updatedClause = factory.updateImportClause(clause, clause.isTypeOnly, clause.name, updatedNamed);
|
|
114
|
+
return factory.updateImportDeclaration(node, node.modifiers, updatedClause, node.moduleSpecifier, node.assertClause);
|
|
115
|
+
}
|
|
116
|
+
function removeNativeClassFromDecorate(statement) {
|
|
117
|
+
const expr = statement.expression;
|
|
118
|
+
if (!expr || !ts.isBinaryExpression(expr) || expr.operatorToken.kind !== ts.SyntaxKind.EqualsToken)
|
|
119
|
+
return statement;
|
|
120
|
+
const right = expr.right;
|
|
121
|
+
if (!ts.isCallExpression(right) || getIdentifierText(right.expression) !== '__decorate' || right.arguments.length === 0)
|
|
122
|
+
return statement;
|
|
123
|
+
const arr = right.arguments[0];
|
|
124
|
+
if (!ts.isArrayLiteralExpression(arr))
|
|
125
|
+
return statement;
|
|
126
|
+
const retained = arr.elements.filter((el) => getIdentifierText(el) !== 'NativeClass');
|
|
127
|
+
if (retained.length === arr.elements.length)
|
|
128
|
+
return statement;
|
|
129
|
+
if (retained.length === 0)
|
|
130
|
+
return undefined;
|
|
131
|
+
const newArr = factory.updateArrayLiteralExpression(arr, retained);
|
|
132
|
+
const newCall = factory.updateCallExpression(right, right.expression, right.typeArguments, [newArr, ...right.arguments.slice(1)]);
|
|
133
|
+
const newBin = factory.updateBinaryExpression(expr, expr.left, expr.operatorToken, newCall);
|
|
134
|
+
return factory.updateExpressionStatement(statement, newBin);
|
|
135
|
+
}
|
|
136
|
+
function visitNode(node) {
|
|
137
|
+
if (ts.isBlock(node)) {
|
|
138
|
+
const [stmts, changed] = transformStatements(node.statements, false);
|
|
139
|
+
return changed ? factory.updateBlock(node, stmts) : node;
|
|
140
|
+
}
|
|
141
|
+
if (ts.isModuleBlock(node)) {
|
|
142
|
+
const [stmts, changed] = transformStatements(node.statements, false);
|
|
143
|
+
return changed ? factory.updateModuleBlock(node, stmts) : node;
|
|
144
|
+
}
|
|
145
|
+
if (ts.isCaseClause(node)) {
|
|
146
|
+
const expr = ts.visitNode(node.expression, visitNode);
|
|
147
|
+
const [stmts, changed] = transformStatements(node.statements, false);
|
|
148
|
+
if (!changed && (expr ?? node.expression) === node.expression)
|
|
149
|
+
return node;
|
|
150
|
+
mutated = true;
|
|
151
|
+
return factory.updateCaseClause(node, (expr ?? node.expression), stmts);
|
|
152
|
+
}
|
|
153
|
+
if (ts.isDefaultClause(node)) {
|
|
154
|
+
const [stmts, changed] = transformStatements(node.statements, false);
|
|
155
|
+
return changed ? factory.updateDefaultClause(node, stmts) : node;
|
|
156
|
+
}
|
|
157
|
+
return ts.visitEachChild(node, visitNode, ctx);
|
|
158
|
+
}
|
|
159
|
+
function transformStatements(statements, isTopLevel) {
|
|
160
|
+
let changed = false;
|
|
161
|
+
const out = [];
|
|
162
|
+
for (const s of statements) {
|
|
163
|
+
if (ts.isClassDeclaration(s) && hasNativeClassDecorator(s)) {
|
|
164
|
+
mutated = true;
|
|
165
|
+
changed = true;
|
|
166
|
+
out.push(...emitDownleveledClass(s));
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (ts.isExpressionStatement(s)) {
|
|
170
|
+
const updated = removeNativeClassFromDecorate(s);
|
|
171
|
+
if (!updated) {
|
|
172
|
+
mutated = true;
|
|
173
|
+
changed = true;
|
|
174
|
+
continue;
|
|
175
|
+
}
|
|
176
|
+
const visited = ts.visitEachChild(updated, visitNode, ctx);
|
|
177
|
+
if (visited !== s) {
|
|
178
|
+
mutated = true;
|
|
179
|
+
changed = true;
|
|
180
|
+
}
|
|
181
|
+
out.push(visited);
|
|
182
|
+
continue;
|
|
183
|
+
}
|
|
184
|
+
if (isTopLevel && ts.isImportDeclaration(s)) {
|
|
185
|
+
const updated = removeNativeClassImport(s);
|
|
186
|
+
if (!updated) {
|
|
187
|
+
mutated = true;
|
|
188
|
+
changed = true;
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (updated !== s) {
|
|
192
|
+
mutated = true;
|
|
193
|
+
changed = true;
|
|
194
|
+
}
|
|
195
|
+
out.push(updated);
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
const visited = ts.visitEachChild(s, visitNode, ctx);
|
|
199
|
+
if (visited !== s) {
|
|
200
|
+
mutated = true;
|
|
201
|
+
changed = true;
|
|
202
|
+
}
|
|
203
|
+
out.push(visited);
|
|
204
|
+
}
|
|
205
|
+
return [changed ? factory.createNodeArray(out) : statements, changed];
|
|
206
|
+
}
|
|
207
|
+
const [updatedStatements] = transformStatements(sourceFile.statements, true);
|
|
208
|
+
if (!mutated)
|
|
209
|
+
return sourceFile;
|
|
210
|
+
const updated = factory.updateSourceFile(sourceFile, updatedStatements);
|
|
211
|
+
const setParentRecursive = (node, parent) => {
|
|
212
|
+
node.parent = parent;
|
|
213
|
+
ts.forEachChild(node, (child) => setParentRecursive(child, node));
|
|
214
|
+
};
|
|
215
|
+
for (const stmt of updated.statements) {
|
|
216
|
+
if (stmt.parent !== updated)
|
|
217
|
+
setParentRecursive(stmt, updated);
|
|
218
|
+
}
|
|
219
|
+
return updated;
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../packages/vite/transformers/NativeClass/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,YAAY,CAAC;AAE5B,mCAAmC;AACnC,+FAA+F;AAC/F,yDAAyD;AACzD,MAAM,CAAC,OAAO,WAAW,GAA6B;IACrD,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,IAAI,EAAE,CAAC,OAAO,CAAC;IAC1C,OAAO,CAAC,UAAyB,EAAE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AE,CAAC,cAAc,CAAC,CAAC,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC;gBACrD,IAAI,OAAO,KAAK,CAAC,EAAE,CAAC;oBACnB,OAAO,GAAG,IAAI,CAAC;oBACf,OAAO,GAAG,IAAI,CAAC;gBAChB,CAAC;gBACD,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACnB,CAAC;YACD,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACvE,CAAC;QAED,MAAM,CAAC,iBAAiB,CAAC,GAAG,mBAAmB,CAAC,UAAU,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC7E,IAAI,CAAC,OAAO;YAAE,OAAO,UAAU,CAAC;QAChC,MAAM,OAAO,GAAG,OAAO,CAAC,gBAAgB,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAC;QACxE,MAAM,kBAAkB,GAAG,CAAC,IAAa,EAAE,MAAe,EAAE,EAAE;YAC5D,IAAY,CAAC,MAAM,GAAG,MAAM,CAAC;YAC9B,EAAE,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;QACnE,CAAC,CAAC;QACF,KAAK,MAAM,IAAI,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvC,IAAK,IAAY,CAAC,MAAM,KAAK,OAAO;gBAAE,kBAAkB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACzE,CAAC;QACD,OAAO,OAAO,CAAC;IAChB,CAAC,CAAC;AACH,CAAC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { mergeConfig } from "vite";
|
|
2
|
-
import path from "path";
|
|
3
|
-
import angular from "@analogjs/vite-plugin-angular";
|
|
4
|
-
import { baseConfig } from "./base.js";
|
|
5
|
-
const plugins = [
|
|
6
|
-
// Allow external html template changes to trigger hot reload: Make .ts files depend on their .html templates
|
|
7
|
-
{
|
|
8
|
-
name: "angular-template-deps",
|
|
9
|
-
transform(code, id) {
|
|
10
|
-
// For .ts files that reference templateUrl, add the .html file as a dependency
|
|
11
|
-
if (id.endsWith(".ts") && code.includes("templateUrl")) {
|
|
12
|
-
const templateUrlMatch = code.match(/templateUrl:\s*['"]\.\/(.*?\.html)['"]/);
|
|
13
|
-
if (templateUrlMatch) {
|
|
14
|
-
const htmlPath = path.resolve(path.dirname(id), templateUrlMatch[1]);
|
|
15
|
-
// Add the HTML file as a dependency so Vite watches it
|
|
16
|
-
this.addWatchFile(htmlPath);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
return null;
|
|
20
|
-
},
|
|
21
|
-
},
|
|
22
|
-
angular({
|
|
23
|
-
liveReload: false, // Disable live reload in favor of HMR
|
|
24
|
-
}),
|
|
25
|
-
];
|
|
26
|
-
export const angularConfig = ({ mode }) => {
|
|
27
|
-
return mergeConfig(baseConfig({ mode }), {
|
|
28
|
-
plugins,
|
|
29
|
-
});
|
|
30
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { UserConfig } from "vite";
|
|
2
|
-
export declare const baseConfig: ({ mode, skipCommonjsPackages, customCommonjsPlugins, commonjsIgnoreList, optimizeDeps, }: {
|
|
3
|
-
mode: string;
|
|
4
|
-
skipCommonjsPackages?: string[];
|
|
5
|
-
customCommonjsPlugins?: {
|
|
6
|
-
name: string;
|
|
7
|
-
enforce: string;
|
|
8
|
-
resolveId(id: any): any;
|
|
9
|
-
load(id: any): string;
|
|
10
|
-
}[];
|
|
11
|
-
commonjsIgnoreList?: string[];
|
|
12
|
-
optimizeDeps?: string[];
|
|
13
|
-
}) => UserConfig;
|
|
@@ -1,228 +0,0 @@
|
|
|
1
|
-
import path from "path";
|
|
2
|
-
import minimist from "minimist";
|
|
3
|
-
import commonjs from "@rollup/plugin-commonjs";
|
|
4
|
-
import NativeScriptPlugin from "../helpers/resolver.js";
|
|
5
|
-
import nsConfigAsJsonPlugin from "../helpers/config-as-json.js";
|
|
6
|
-
import { getProjectRootPath } from "../helpers/project.js";
|
|
7
|
-
import { aliasCssTree } from "../helpers/css-tree.js";
|
|
8
|
-
import { packagePlatformAliases } from "../helpers/package-platform-aliases.js";
|
|
9
|
-
import { getGlobalDefines } from "../helpers/global-defines.js";
|
|
10
|
-
import { getWorkerPlugins, workerUrlPlugin } from "../helpers/workers.js";
|
|
11
|
-
import { getTsConfigData } from "../helpers/ts-config-paths.js";
|
|
12
|
-
import { commonjsPlugins } from "../helpers/commonjs-plugins.js";
|
|
13
|
-
import { nativescriptPackageResolver } from "../helpers/nativescript-package-resolver.js";
|
|
14
|
-
import { hmrPlugin, cliPlugin } from "../helpers/ns-cli-plugins.js";
|
|
15
|
-
import { dynamicImportPlugin } from "../helpers/dynamic-import-plugin.js";
|
|
16
|
-
import { mainEntryPlugin } from "../helpers/main-entry.js";
|
|
17
|
-
import { determineProjectFlavor } from "../helpers/flavor.js";
|
|
18
|
-
const debugViteLogs = !!process.env.VITE_DEBUG_PATHS;
|
|
19
|
-
const projectRoot = getProjectRootPath();
|
|
20
|
-
export const baseConfig = ({ mode, skipCommonjsPackages, customCommonjsPlugins, commonjsIgnoreList, optimizeDeps, }) => {
|
|
21
|
-
const platform = mode;
|
|
22
|
-
const targetMode = process.env.production ? "production" : "development";
|
|
23
|
-
const cliArgs = minimist(process.argv.slice(2), { "--": true });
|
|
24
|
-
const cliFlags = (cliArgs["--"] || []).reduce((obj, flag) => {
|
|
25
|
-
// remove env prefix
|
|
26
|
-
const [rawKey, ...rest] = flag.replace(/^--env\./, "").split("=");
|
|
27
|
-
obj[rawKey] = rest.length === 0 ? true : rest.join("=");
|
|
28
|
-
return obj;
|
|
29
|
-
}, {});
|
|
30
|
-
console.log("cliFlags:", cliFlags);
|
|
31
|
-
const debug = !!cliFlags.viteDebug || !!process.env.DEBUG || targetMode === "development";
|
|
32
|
-
if (debug) {
|
|
33
|
-
console.log("--------------");
|
|
34
|
-
console.log("Vite config mode:", mode);
|
|
35
|
-
console.log("Target mode:", targetMode);
|
|
36
|
-
console.log("Platform:", platform);
|
|
37
|
-
console.log("--------------");
|
|
38
|
-
}
|
|
39
|
-
const flavor = determineProjectFlavor();
|
|
40
|
-
console.log(`Building for ${flavor}.`);
|
|
41
|
-
// Create TypeScript aliases with platform support
|
|
42
|
-
const tsConfigData = getTsConfigData(debugViteLogs, platform);
|
|
43
|
-
// Common resolve configuration for both main and worker builds
|
|
44
|
-
const resolveConfig = {
|
|
45
|
-
// ensures Vite prefers ESM entry‑points
|
|
46
|
-
mainFields: ["module", "main"],
|
|
47
|
-
// Make sure ESM conditions win during resolution
|
|
48
|
-
conditions: ["module", "import", "browser", "default"],
|
|
49
|
-
// use this with merge config instead or could list common dedupes in base here altogether
|
|
50
|
-
dedupe: ["@nativescript/core", "nativescript-vue", "vue"],
|
|
51
|
-
// Alias "@" and "~" to your src directory for cleaner imports
|
|
52
|
-
alias: [
|
|
53
|
-
...aliasCssTree,
|
|
54
|
-
// 1) Catch exactly `~/package.json` → virtual module (MUST be first!)
|
|
55
|
-
{ find: /^~\/package\.json$/, replacement: "~/package.json" },
|
|
56
|
-
// TypeScript path aliases from tsconfig.json
|
|
57
|
-
...tsConfigData.aliases,
|
|
58
|
-
// Generic platform resolution for any npm package
|
|
59
|
-
packagePlatformAliases(tsConfigData, platform, skipCommonjsPackages, debugViteLogs),
|
|
60
|
-
// 2) Catch everything else under "~/" → your src/
|
|
61
|
-
{ find: /^~\/(.*)$/, replacement: path.resolve(projectRoot, "src/$1") },
|
|
62
|
-
// optional: "@" → src/
|
|
63
|
-
{ find: "@", replacement: path.resolve(projectRoot, "src") },
|
|
64
|
-
],
|
|
65
|
-
extensions: [
|
|
66
|
-
".ios.tsx",
|
|
67
|
-
".android.tsx",
|
|
68
|
-
".tsx",
|
|
69
|
-
".ios.jsx",
|
|
70
|
-
".android.jsx",
|
|
71
|
-
".jsx",
|
|
72
|
-
".ios.ts",
|
|
73
|
-
".android.ts",
|
|
74
|
-
".ts",
|
|
75
|
-
".ios.js",
|
|
76
|
-
".android.js",
|
|
77
|
-
".js",
|
|
78
|
-
".mjs",
|
|
79
|
-
".json",
|
|
80
|
-
],
|
|
81
|
-
preserveSymlinks: true,
|
|
82
|
-
};
|
|
83
|
-
// Common define configuration for both main and worker builds
|
|
84
|
-
const defineConfig = getGlobalDefines(platform, targetMode);
|
|
85
|
-
return {
|
|
86
|
-
resolve: resolveConfig,
|
|
87
|
-
define: defineConfig,
|
|
88
|
-
// Vite's built-in solution for CommonJS/ESM compatibility issues
|
|
89
|
-
optimizeDeps: {
|
|
90
|
-
// Force pre-bundling of problematic CommonJS packages
|
|
91
|
-
include: [
|
|
92
|
-
// "source-map-js",
|
|
93
|
-
"@valor/nativescript-websockets",
|
|
94
|
-
// React and related packages for proper module resolution
|
|
95
|
-
"react",
|
|
96
|
-
"react-reconciler",
|
|
97
|
-
"react-nativescript",
|
|
98
|
-
...(optimizeDeps || []),
|
|
99
|
-
// Add any other problematic packages here
|
|
100
|
-
],
|
|
101
|
-
// Handle Node.js built-ins and other edge cases
|
|
102
|
-
esbuildOptions: {
|
|
103
|
-
// Pass the same conditions to ESBuild for css-tree compatibility
|
|
104
|
-
conditions: ["module", "import", "browser", "default"],
|
|
105
|
-
// Define globals for Node.js built-ins if needed
|
|
106
|
-
define: {
|
|
107
|
-
global: "globalThis",
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
plugins: [
|
|
112
|
-
// TODO: make flavor plugins dynamic
|
|
113
|
-
// ...flavorPlugins,
|
|
114
|
-
...commonjsPlugins,
|
|
115
|
-
...(customCommonjsPlugins || []),
|
|
116
|
-
// Platform-specific package resolver - MUST come before commonjs plugin
|
|
117
|
-
nativescriptPackageResolver(platform),
|
|
118
|
-
// Simplified CommonJS handling - let Vite's optimizeDeps do the heavy lifting
|
|
119
|
-
commonjs({
|
|
120
|
-
include: [/node_modules/],
|
|
121
|
-
// Force specific problematic modules to be treated as CommonJS
|
|
122
|
-
requireReturnsDefault: "auto",
|
|
123
|
-
defaultIsModuleExports: "auto",
|
|
124
|
-
transformMixedEsModules: true,
|
|
125
|
-
// Ignore optional dependencies that are meant to fail gracefully
|
|
126
|
-
ignore: [
|
|
127
|
-
"@nativescript/android",
|
|
128
|
-
"@nativescript/ios",
|
|
129
|
-
...(commonjsIgnoreList || []),
|
|
130
|
-
],
|
|
131
|
-
}),
|
|
132
|
-
nsConfigAsJsonPlugin(),
|
|
133
|
-
NativeScriptPlugin({ platform }),
|
|
134
|
-
mainEntryPlugin(cliFlags, debug),
|
|
135
|
-
// NativeScript HMR integration - track changes for incremental builds
|
|
136
|
-
hmrPlugin(targetMode),
|
|
137
|
-
// NativeScript CLI integration - enhanced IPC communication for HMR
|
|
138
|
-
cliPlugin(targetMode, cliFlags),
|
|
139
|
-
dynamicImportPlugin(),
|
|
140
|
-
// Transform Vite worker URLs to NativeScript format AFTER bundling
|
|
141
|
-
workerUrlPlugin(),
|
|
142
|
-
],
|
|
143
|
-
css: {
|
|
144
|
-
postcss: "./postcss.config.js",
|
|
145
|
-
},
|
|
146
|
-
// Development server configuration for HMR
|
|
147
|
-
server: targetMode === "development"
|
|
148
|
-
? {
|
|
149
|
-
hmr: {
|
|
150
|
-
// Enable Vite's built-in HMR
|
|
151
|
-
port: 24678, // Different port to avoid conflicts with our custom WebSocket
|
|
152
|
-
},
|
|
153
|
-
// CORS for development
|
|
154
|
-
cors: true,
|
|
155
|
-
}
|
|
156
|
-
: {},
|
|
157
|
-
// Configure worker builds to bundle everything into standalone workers
|
|
158
|
-
worker: {
|
|
159
|
-
format: "es",
|
|
160
|
-
plugins: () => getWorkerPlugins(platform),
|
|
161
|
-
rollupOptions: {
|
|
162
|
-
// Don't externalize anything - bundle everything into the worker
|
|
163
|
-
external: [],
|
|
164
|
-
output: {
|
|
165
|
-
// Inline all dynamic imports to create standalone bundle
|
|
166
|
-
inlineDynamicImports: true,
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
},
|
|
170
|
-
build: {
|
|
171
|
-
target: "esnext",
|
|
172
|
-
minify: !debug,
|
|
173
|
-
// Generate source maps for debugging
|
|
174
|
-
// Note: just disabling for now until can hook up to angular vite/analog plugin
|
|
175
|
-
sourcemap: false, //debug,
|
|
176
|
-
// Disable module preloading to avoid browser APIs
|
|
177
|
-
modulePreload: false,
|
|
178
|
-
// Optimize for development speed
|
|
179
|
-
...(targetMode === "development" && {
|
|
180
|
-
// Faster builds in development
|
|
181
|
-
reportCompressedSize: false,
|
|
182
|
-
chunkSizeWarningLimit: 2000,
|
|
183
|
-
}),
|
|
184
|
-
commonjsOptions: {
|
|
185
|
-
include: [/node_modules/],
|
|
186
|
-
},
|
|
187
|
-
rollupOptions: {
|
|
188
|
-
input: "virtual:entry-with-polyfills",
|
|
189
|
-
output: {
|
|
190
|
-
dir: path.resolve(projectRoot, "dist"),
|
|
191
|
-
format: "es", // Emit ES modules (.mjs)
|
|
192
|
-
entryFileNames: "bundle.mjs", // <- no hash here
|
|
193
|
-
chunkFileNames: (chunk) => {
|
|
194
|
-
if (chunk.name === "vendor")
|
|
195
|
-
return "vendor.mjs";
|
|
196
|
-
// Place worker files at root level, not in assets/
|
|
197
|
-
if (chunk.name && chunk.name.includes("worker")) {
|
|
198
|
-
return "[name]-[hash].js";
|
|
199
|
-
}
|
|
200
|
-
return "[name]-[hash].mjs";
|
|
201
|
-
},
|
|
202
|
-
assetFileNames: "assets/[name][extname]",
|
|
203
|
-
// Create single vendor chunk - no separate globals chunk to avoid circular deps
|
|
204
|
-
manualChunks(id) {
|
|
205
|
-
if (id.includes("node_modules")) {
|
|
206
|
-
// Note: this is work in progress on best setup
|
|
207
|
-
// Keep polyfills and Zone-dependent packages in main bundle to ensure correct execution order
|
|
208
|
-
if ([
|
|
209
|
-
"@nativescript/core",
|
|
210
|
-
"@nativescript/angular",
|
|
211
|
-
"@nativescript/zone-js",
|
|
212
|
-
"@valor/nativescript-websockets",
|
|
213
|
-
"make-error",
|
|
214
|
-
// "source-map-js",
|
|
215
|
-
"zone.js",
|
|
216
|
-
"/globals",
|
|
217
|
-
"/polyfills",
|
|
218
|
-
].includes(id)) {
|
|
219
|
-
return undefined; // Keep in main bundle
|
|
220
|
-
}
|
|
221
|
-
return "vendor";
|
|
222
|
-
}
|
|
223
|
-
},
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { UserConfig } from "vite";
|
|
2
|
-
export declare const baseConfig: ({ mode, skipCommonjsPackages, customCommonjsPlugins, commonjsIgnoreList, optimizeDeps, }: {
|
|
3
|
-
mode: string;
|
|
4
|
-
skipCommonjsPackages?: string[];
|
|
5
|
-
customCommonjsPlugins?: {
|
|
6
|
-
name: string;
|
|
7
|
-
enforce: string;
|
|
8
|
-
resolveId(id: any): any;
|
|
9
|
-
load(id: any): string;
|
|
10
|
-
}[];
|
|
11
|
-
commonjsIgnoreList?: string[];
|
|
12
|
-
optimizeDeps?: string[];
|
|
13
|
-
}) => UserConfig;
|