@tamagui/vite-plugin 1.0.17 → 1.0.18

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/cjs/index.js CHANGED
@@ -17,4 +17,5 @@ var src_exports = {};
17
17
  module.exports = __toCommonJS(src_exports);
18
18
  __reExport(src_exports, require("./plugin.js"), module.exports);
19
19
  __reExport(src_exports, require("./extract.js"), module.exports);
20
+ __reExport(src_exports, require("./native.js"), module.exports);
20
21
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './plugin.js'\nexport * from './extract.js'\n"],
5
- "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,wBAAd;AACA,wBAAc,yBADd;",
4
+ "sourcesContent": ["export * from './plugin.js'\nexport * from './extract.js'\nexport * from './native.js'\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,wBAAd;AACA,wBAAc,yBADd;AAEA,wBAAc,wBAFd;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,97 @@
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 native_exports = {};
20
+ __export(native_exports, {
21
+ nativePlugin: () => nativePlugin,
22
+ replaceCss: () => replaceCss,
23
+ replaceScript: () => replaceScript
24
+ });
25
+ module.exports = __toCommonJS(native_exports);
26
+ function replaceScript(html, scriptFilename, scriptCode, removeViteModuleLoader = false) {
27
+ const reScript = new RegExp(
28
+ `<script([^>]*?) src="[./]*${scriptFilename}"([^>]*)><\/script>`
29
+ );
30
+ const preloadMarker = /"__VITE_PRELOAD__"/g;
31
+ const newCode = scriptCode.replace(preloadMarker, "void 0");
32
+ const inlined = html.replace(
33
+ reScript,
34
+ (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>
35
+ ${newCode}
36
+ <\/script>`
37
+ );
38
+ return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined;
39
+ }
40
+ function replaceCss(html, scriptFilename, scriptCode) {
41
+ const reCss = new RegExp(`<link[^>]*? href="[./]*${scriptFilename}"[^>]*?>`);
42
+ const inlined = html.replace(reCss, `<style>
43
+ ${scriptCode}
44
+ </style>`);
45
+ return inlined;
46
+ }
47
+ const warnNotInlined = (filename) => console.warn(`WARNING: asset not inlined: ${filename}`);
48
+ function nativePlugin() {
49
+ return {
50
+ name: "vite:singlefile",
51
+ config: (config) => {
52
+ if (!config.build)
53
+ config.build = {};
54
+ config.build.assetsInlineLimit = 1e8;
55
+ config.build.chunkSizeWarningLimit = 1e8;
56
+ config.build.cssCodeSplit = false;
57
+ config.build.reportCompressedSize = false;
58
+ config.base = void 0;
59
+ if (!config.build.rollupOptions)
60
+ config.build.rollupOptions = {};
61
+ if (!config.build.rollupOptions.output)
62
+ config.build.rollupOptions.output = {};
63
+ const updateOutputOptions = (out) => {
64
+ out.inlineDynamicImports = true;
65
+ console.log("adding manualChunks = undefined");
66
+ out.manualChunks = void 0;
67
+ };
68
+ if (Array.isArray(config.build.rollupOptions.output)) {
69
+ for (const o in config.build.rollupOptions.output)
70
+ updateOutputOptions(o);
71
+ } else {
72
+ updateOutputOptions(config.build.rollupOptions.output);
73
+ }
74
+ },
75
+ enforce: "post",
76
+ generateBundle: (_, bundle) => {
77
+ const inlinePattern = [];
78
+ const jsExtensionTest = /\.[mc]?js$/;
79
+ const htmlFiles = Object.keys(bundle).filter((i) => i.endsWith(".html"));
80
+ const cssAssets = Object.keys(bundle).filter((i) => i.endsWith(".css"));
81
+ const jsAssets = Object.keys(bundle).filter((i) => jsExtensionTest.test(i));
82
+ const bundlesToDelete = [];
83
+ console.log("bundle", bundle);
84
+ }
85
+ };
86
+ }
87
+ const _removeViteModuleLoader = (html) => html.replace(
88
+ /(<script type="module" crossorigin>\s*)\(function\(\)\{[\s\S]*?\}\)\(\);/,
89
+ '<script type="module">\n'
90
+ );
91
+ // Annotate the CommonJS export names for ESM import in node:
92
+ 0 && (module.exports = {
93
+ nativePlugin,
94
+ replaceCss,
95
+ replaceScript
96
+ });
97
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/native.ts"],
4
+ "sourcesContent": ["// testing single file logic via https://github.com/richardtallent/vite-plugin-singlefile\n\n// helpful:\n// rollup config for react native\n// https://gist.github.com/pritishvaidya/171dcb8e857ec1df186c035c3df6ae16\n\nimport micromatch from 'micromatch'\nimport { OutputAsset, OutputChunk, OutputOptions } from 'rollup'\nimport { Plugin } from 'vite'\n\nexport function replaceScript(\n html: string,\n scriptFilename: string,\n scriptCode: string,\n removeViteModuleLoader = false\n): string {\n const reScript = new RegExp(\n `<script([^>]*?) src=\"[./]*${scriptFilename}\"([^>]*)></script>`\n )\n // we can't use String.prototype.replaceAll since it isn't supported in Node.JS 14\n const preloadMarker = /\"__VITE_PRELOAD__\"/g\n const newCode = scriptCode.replace(preloadMarker, 'void 0')\n const inlined = html.replace(\n reScript,\n (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>\\n${newCode}\\n</script>`\n )\n return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined\n}\n\nexport function replaceCss(\n html: string,\n scriptFilename: string,\n scriptCode: string\n): string {\n const reCss = new RegExp(`<link[^>]*? href=\"[./]*${scriptFilename}\"[^>]*?>`)\n const inlined = html.replace(reCss, `<style>\\n${scriptCode}\\n</style>`)\n return inlined\n}\n\nconst warnNotInlined = (filename: string) =>\n console.warn(`WARNING: asset not inlined: ${filename}`)\n\nexport function nativePlugin(): Plugin {\n return {\n name: 'vite:singlefile',\n config: (config) => {\n if (!config.build) config.build = {}\n // Ensures that even very large assets are inlined in your JavaScript.\n config.build.assetsInlineLimit = 100000000\n // Avoid warnings about large chunks.\n config.build.chunkSizeWarningLimit = 100000000\n // Emit all CSS as a single file, which `vite-plugin-singlefile` can then inline.\n config.build.cssCodeSplit = false\n // Avoids the extra step of testing Brotli compression, which isn't really pertinent to a file served locally.\n config.build.reportCompressedSize = false\n // Subfolder bases are not supported, and shouldn't be needed because we're embedding everything.\n config.base = undefined\n\n if (!config.build.rollupOptions) config.build.rollupOptions = {}\n if (!config.build.rollupOptions.output) config.build.rollupOptions.output = {}\n\n const updateOutputOptions = (out: OutputOptions) => {\n // Ensure that as many resources as possible are inlined.\n out.inlineDynamicImports = true\n\n // added by me (nate):\n console.log('adding manualChunks = undefined')\n out.manualChunks = undefined\n }\n\n if (Array.isArray(config.build.rollupOptions.output)) {\n for (const o in config.build.rollupOptions.output)\n updateOutputOptions(o as OutputOptions)\n } else {\n updateOutputOptions(config.build.rollupOptions.output as OutputOptions)\n }\n },\n\n enforce: 'post',\n\n generateBundle: (_, bundle) => {\n const inlinePattern = []\n const jsExtensionTest = /\\.[mc]?js$/\n const htmlFiles = Object.keys(bundle).filter((i) => i.endsWith('.html'))\n const cssAssets = Object.keys(bundle).filter((i) => i.endsWith('.css'))\n const jsAssets = Object.keys(bundle).filter((i) => jsExtensionTest.test(i))\n const bundlesToDelete = [] as string[]\n\n console.log('bundle', bundle)\n\n // for (const name of htmlFiles) {\n // const htmlChunk = bundle[name] as OutputAsset\n // let replacedHtml = htmlChunk.source as string\n // for (const jsName of jsAssets) {\n // if (!inlinePattern.length || micromatch.isMatch(jsName, inlinePattern)) {\n // const jsChunk = bundle[jsName] as OutputChunk\n // if (jsChunk.code != null) {\n // bundlesToDelete.push(jsName)\n // replacedHtml = replaceScript(\n // replacedHtml,\n // jsChunk.fileName,\n // jsChunk.code,\n // false\n // // removeViteModuleLoader\n // )\n // }\n // } else {\n // warnNotInlined(jsName)\n // }\n // }\n // for (const cssName of cssAssets) {\n // if (!inlinePattern.length || micromatch.isMatch(cssName, inlinePattern)) {\n // const cssChunk = bundle[cssName] as OutputAsset\n // bundlesToDelete.push(cssName)\n // replacedHtml = replaceCss(\n // replacedHtml,\n // cssChunk.fileName,\n // cssChunk.source as string\n // )\n // } else {\n // warnNotInlined(cssName)\n // }\n // }\n // htmlChunk.source = replacedHtml\n // }\n\n // if (deleteInlinedFiles) {\n // for (const name of bundlesToDelete) {\n // delete bundle[name]\n // }\n // }\n\n // for (const name of Object.keys(bundle).filter(\n // (i) => !jsExtensionTest.test(i) && !i.endsWith('.css') && !i.endsWith('.html')\n // )) {\n // warnNotInlined(name)\n // }\n },\n }\n}\n\n// Optionally remove the Vite module loader since it's no longer needed because this plugin has inlined all code.\n// This assumes that the Module Loader is (1) the FIRST function declared in the module, (2) an IIFE, (3) is minified,\n// (4) is within a script with no unexpected attribute values, and (5) that the containing script is the first script\n// tag that matches the above criteria. Changes to the SCRIPT tag especially could break this again in the future.\n// Update example:\n// https://github.com/richardtallent/vite-plugin-singlefile/issues/57#issuecomment-1263950209\nconst _removeViteModuleLoader = (html: string) =>\n html.replace(\n /(<script type=\"module\" crossorigin>\\s*)\\(function\\(\\)\\{[\\s\\S]*?\\}\\)\\(\\);/,\n '<script type=\"module\">\\n'\n )\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUO,SAAS,cACd,MACA,gBACA,YACA,yBAAyB,OACjB;AACR,QAAM,WAAW,IAA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AG,WAAW;AAC7B,YAAM,gBAAgB,CAAC;AACvB,YAAM,kBAAkB;AACxB,YAAM,YAAY,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,OAAO,CAAC;AACvE,YAAM,YAAY,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,SAAS,MAAM,CAAC;AACtE,YAAM,WAAW,OAAO,KAAK,MAAM,EAAE,OAAO,CAAC,MAAM,gBAAgB,KAAK,CAAC,CAAC;AAC1E,YAAM,kBAAkB,CAAC;AAEzB,cAAQ,IAAI,UAAU,MAAM;AAAA,IAiD9B;AAAA,EACF;AACF;AAQA,MAAM,0BAA0B,CAAC,SAC/B,KAAK;AAAA,EACH;AAAA,EACA;AACF;",
6
+ "names": []
7
+ }
package/dist/esm/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./plugin.js";
2
2
  export * from "./extract.js";
3
+ export * from "./native.js";
3
4
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from './plugin.js'\nexport * from './extract.js'\n"],
5
- "mappings": "AAAA,cAAc;AACd,cAAc;",
4
+ "sourcesContent": ["export * from './plugin.js'\nexport * from './extract.js'\nexport * from './native.js'\n"],
5
+ "mappings": "AAAA,cAAc;AACd,cAAc;AACd,cAAc;",
6
6
  "names": []
7
7
  }
@@ -0,0 +1,71 @@
1
+ function replaceScript(html, scriptFilename, scriptCode, removeViteModuleLoader = false) {
2
+ const reScript = new RegExp(
3
+ `<script([^>]*?) src="[./]*${scriptFilename}"([^>]*)><\/script>`
4
+ );
5
+ const preloadMarker = /"__VITE_PRELOAD__"/g;
6
+ const newCode = scriptCode.replace(preloadMarker, "void 0");
7
+ const inlined = html.replace(
8
+ reScript,
9
+ (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>
10
+ ${newCode}
11
+ <\/script>`
12
+ );
13
+ return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined;
14
+ }
15
+ function replaceCss(html, scriptFilename, scriptCode) {
16
+ const reCss = new RegExp(`<link[^>]*? href="[./]*${scriptFilename}"[^>]*?>`);
17
+ const inlined = html.replace(reCss, `<style>
18
+ ${scriptCode}
19
+ </style>`);
20
+ return inlined;
21
+ }
22
+ const warnNotInlined = (filename) => console.warn(`WARNING: asset not inlined: ${filename}`);
23
+ function nativePlugin() {
24
+ return {
25
+ name: "vite:singlefile",
26
+ config: (config) => {
27
+ if (!config.build)
28
+ config.build = {};
29
+ config.build.assetsInlineLimit = 1e8;
30
+ config.build.chunkSizeWarningLimit = 1e8;
31
+ config.build.cssCodeSplit = false;
32
+ config.build.reportCompressedSize = false;
33
+ config.base = void 0;
34
+ if (!config.build.rollupOptions)
35
+ config.build.rollupOptions = {};
36
+ if (!config.build.rollupOptions.output)
37
+ config.build.rollupOptions.output = {};
38
+ const updateOutputOptions = (out) => {
39
+ out.inlineDynamicImports = true;
40
+ console.log("adding manualChunks = undefined");
41
+ out.manualChunks = void 0;
42
+ };
43
+ if (Array.isArray(config.build.rollupOptions.output)) {
44
+ for (const o in config.build.rollupOptions.output)
45
+ updateOutputOptions(o);
46
+ } else {
47
+ updateOutputOptions(config.build.rollupOptions.output);
48
+ }
49
+ },
50
+ enforce: "post",
51
+ generateBundle: (_, bundle) => {
52
+ const inlinePattern = [];
53
+ const jsExtensionTest = /\.[mc]?js$/;
54
+ const htmlFiles = Object.keys(bundle).filter((i) => i.endsWith(".html"));
55
+ const cssAssets = Object.keys(bundle).filter((i) => i.endsWith(".css"));
56
+ const jsAssets = Object.keys(bundle).filter((i) => jsExtensionTest.test(i));
57
+ const bundlesToDelete = [];
58
+ console.log("bundle", bundle);
59
+ }
60
+ };
61
+ }
62
+ const _removeViteModuleLoader = (html) => html.replace(
63
+ /(<script type="module" crossorigin>\s*)\(function\(\)\{[\s\S]*?\}\)\(\);/,
64
+ '<script type="module">\n'
65
+ );
66
+ export {
67
+ nativePlugin,
68
+ replaceCss,
69
+ replaceScript
70
+ };
71
+ //# sourceMappingURL=native.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/native.ts"],
4
+ "sourcesContent": ["// testing single file logic via https://github.com/richardtallent/vite-plugin-singlefile\n\n// helpful:\n// rollup config for react native\n// https://gist.github.com/pritishvaidya/171dcb8e857ec1df186c035c3df6ae16\n\nimport micromatch from 'micromatch'\nimport { OutputAsset, OutputChunk, OutputOptions } from 'rollup'\nimport { Plugin } from 'vite'\n\nexport function replaceScript(\n html: string,\n scriptFilename: string,\n scriptCode: string,\n removeViteModuleLoader = false\n): string {\n const reScript = new RegExp(\n `<script([^>]*?) src=\"[./]*${scriptFilename}\"([^>]*)></script>`\n )\n // we can't use String.prototype.replaceAll since it isn't supported in Node.JS 14\n const preloadMarker = /\"__VITE_PRELOAD__\"/g\n const newCode = scriptCode.replace(preloadMarker, 'void 0')\n const inlined = html.replace(\n reScript,\n (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>\\n${newCode}\\n</script>`\n )\n return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined\n}\n\nexport function replaceCss(\n html: string,\n scriptFilename: string,\n scriptCode: string\n): string {\n const reCss = new RegExp(`<link[^>]*? href=\"[./]*${scriptFilename}\"[^>]*?>`)\n const inlined = html.replace(reCss, `<style>\\n${scriptCode}\\n</style>`)\n return inlined\n}\n\nconst warnNotInlined = (filename: string) =>\n console.warn(`WARNING: asset not inlined: ${filename}`)\n\nexport function nativePlugin(): Plugin {\n return {\n name: 'vite:singlefile',\n config: (config) => {\n if (!config.build) config.build = {}\n // Ensures that even very large assets are inlined in your JavaScript.\n config.build.assetsInlineLimit = 100000000\n // Avoid warnings about large chunks.\n config.build.chunkSizeWarningLimit = 100000000\n // Emit all CSS as a single file, which `vite-plugin-singlefile` can then inline.\n config.build.cssCodeSplit = false\n // Avoids the extra step of testing Brotli compression, which isn't really pertinent to a file served locally.\n config.build.reportCompressedSize = false\n // Subfolder bases are not supported, and shouldn't be needed because we're embedding everything.\n config.base = undefined\n\n if (!config.build.rollupOptions) config.build.rollupOptions = {}\n if (!config.build.rollupOptions.output) config.build.rollupOptions.output = {}\n\n const updateOutputOptions = (out: OutputOptions) => {\n // Ensure that as many resources as possible are inlined.\n out.inlineDynamicImports = true\n\n // added by me (nate):\n console.log('adding manualChunks = undefined')\n out.manualChunks = undefined\n }\n\n if (Array.isArray(config.build.rollupOptions.output)) {\n for (const o in config.build.rollupOptions.output)\n updateOutputOptions(o as OutputOptions)\n } else {\n updateOutputOptions(config.build.rollupOptions.output as OutputOptions)\n }\n },\n\n enforce: 'post',\n\n generateBundle: (_, bundle) => {\n const inlinePattern = []\n const jsExtensionTest = /\\.[mc]?js$/\n const htmlFiles = Object.keys(bundle).filter((i) => i.endsWith('.html'))\n const cssAssets = Object.keys(bundle).filter((i) => i.endsWith('.css'))\n const jsAssets = Object.keys(bundle).filter((i) => jsExtensionTest.test(i))\n const bundlesToDelete = [] as string[]\n\n console.log('bundle', bundle)\n\n // for (const name of htmlFiles) {\n // const htmlChunk = bundle[name] as OutputAsset\n // let replacedHtml = htmlChunk.source as string\n // for (const jsName of jsAssets) {\n // if (!inlinePattern.length || micromatch.isMatch(jsName, inlinePattern)) {\n // const jsChunk = bundle[jsName] as OutputChunk\n // if (jsChunk.code != null) {\n // bundlesToDelete.push(jsName)\n // replacedHtml = replaceScript(\n // replacedHtml,\n // jsChunk.fileName,\n // jsChunk.code,\n // false\n // // removeViteModuleLoader\n // )\n // }\n // } else {\n // warnNotInlined(jsName)\n // }\n // }\n // for (const cssName of cssAssets) {\n // if (!inlinePattern.length || micromatch.isMatch(cssName, inlinePattern)) {\n // const cssChunk = bundle[cssName] as OutputAsset\n // bundlesToDelete.push(cssName)\n // replacedHtml = replaceCss(\n // replacedHtml,\n // cssChunk.fileName,\n // cssChunk.source as string\n // )\n // } else {\n // warnNotInlined(cssName)\n // }\n // }\n // htmlChunk.source = replacedHtml\n // }\n\n // if (deleteInlinedFiles) {\n // for (const name of bundlesToDelete) {\n // delete bundle[name]\n // }\n // }\n\n // for (const name of Object.keys(bundle).filter(\n // (i) => !jsExtensionTest.test(i) && !i.endsWith('.css') && !i.endsWith('.html')\n // )) {\n // warnNotInlined(name)\n // }\n },\n }\n}\n\n// Optionally remove the Vite module loader since it's no longer needed because this plugin has inlined all code.\n// This assumes that the Module Loader is (1) the FIRST function declared in the module, (2) an IIFE, (3) is minified,\n// (4) is within a script with no unexpected attribute values, and (5) that the containing script is the first script\n// tag that matches the above criteria. Changes to the SCRIPT tag especially could break this again in the future.\n// Update example:\n// https://github.com/richardtallent/vite-plugin-singlefile/issues/57#issuecomment-1263950209\nconst _removeViteModuleLoader = (html: string) =>\n html.replace(\n /(<script type=\"module\" crossorigin>\\s*)\\(function\\(\\)\\{[\\s\\S]*?\\}\\)\\(\\);/,\n '<script type=\"module\">\\n'\n )\n"],
5
+ "mappings": "AAUO,SAAS,cACd,MACA,gBACA,YACA,yBAAyB,OACjB;AACR,QAAM,WAAW,IAAI;AAAA,IACnB,6BAA6B;AAAA,EAC/B;AAEA,QAAM,gBAAgB;AACtB,QAAM,UAAU,WAAW,QAAQ,eAAe,QAAQ;AAC1D,QAAM,UAAU,KAAK;AAAA,IACnB;AAAA,IACA,CAAC,GAAG,WAAW,aAAa,UAAU,YAAY;AAAA,EAAc;AAAA;AAAA,EAClE;AACA,SAAO,yBAAyB,wBAAwB,OAAO,IAAI;AACrE;AAEO,SAAS,WACd,MACA,gBACA,YACQ;AACR,QAAM,QAAQ,IAAI,OAAO,0BAA0B,wBAAwB;AAC3E,QAAM,UAAU,KAAK,QAAQ,OAAO;AAAA,EAAY;AAAA,SAAsB;AACtE,SAAO;AACT;AAEA,MAAM,iBAAiB,CAAC,aACtB,QAAQ,KAAK,+BAA+B,UAAU;AAEjD,SAAS,eAAuB;AACrC,SAAO;AAAA,IACL,MAAM;AAAA,IACN,QAAQ,CAAC,WAA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
- "version": "1.0.17",
3
+ "version": "1.0.18",
4
4
  "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
@@ -25,16 +25,18 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@originjs/vite-plugin-commonjs": "^1.0.3",
28
- "@tamagui/fake-react-native": "^1.0.17",
29
- "@tamagui/proxy-worm": "^1.0.17",
30
- "@tamagui/react-native-svg": "^1.0.17",
31
- "@tamagui/static": "^1.0.17",
28
+ "@tamagui/fake-react-native": "^1.0.18",
29
+ "@tamagui/proxy-worm": "^1.0.18",
30
+ "@tamagui/react-native-svg": "^1.0.18",
31
+ "@tamagui/static": "^1.0.18",
32
32
  "fs-extra": "^10.1.0",
33
33
  "lodash": "^4.17.21",
34
- "outdent": "^0.8.0"
34
+ "micromatch": ">=4.0.0",
35
+ "outdent": "^0.8.0",
36
+ "rollup": ">=3.7.0"
35
37
  },
36
38
  "devDependencies": {
37
- "@tamagui/build": "^1.0.17",
39
+ "@tamagui/build": "^1.0.18",
38
40
  "vite-plugin-environment": "^1.1.3"
39
41
  },
40
42
  "publishConfig": {
package/src/index.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './plugin.js'
2
2
  export * from './extract.js'
3
+ export * from './native.js'
package/src/native.ts ADDED
@@ -0,0 +1,152 @@
1
+ // testing single file logic via https://github.com/richardtallent/vite-plugin-singlefile
2
+
3
+ // helpful:
4
+ // rollup config for react native
5
+ // https://gist.github.com/pritishvaidya/171dcb8e857ec1df186c035c3df6ae16
6
+
7
+ import micromatch from 'micromatch'
8
+ import { OutputAsset, OutputChunk, OutputOptions } from 'rollup'
9
+ import { Plugin } from 'vite'
10
+
11
+ export function replaceScript(
12
+ html: string,
13
+ scriptFilename: string,
14
+ scriptCode: string,
15
+ removeViteModuleLoader = false
16
+ ): string {
17
+ const reScript = new RegExp(
18
+ `<script([^>]*?) src="[./]*${scriptFilename}"([^>]*)></script>`
19
+ )
20
+ // we can't use String.prototype.replaceAll since it isn't supported in Node.JS 14
21
+ const preloadMarker = /"__VITE_PRELOAD__"/g
22
+ const newCode = scriptCode.replace(preloadMarker, 'void 0')
23
+ const inlined = html.replace(
24
+ reScript,
25
+ (_, beforeSrc, afterSrc) => `<script${beforeSrc}${afterSrc}>\n${newCode}\n</script>`
26
+ )
27
+ return removeViteModuleLoader ? _removeViteModuleLoader(inlined) : inlined
28
+ }
29
+
30
+ export function replaceCss(
31
+ html: string,
32
+ scriptFilename: string,
33
+ scriptCode: string
34
+ ): string {
35
+ const reCss = new RegExp(`<link[^>]*? href="[./]*${scriptFilename}"[^>]*?>`)
36
+ const inlined = html.replace(reCss, `<style>\n${scriptCode}\n</style>`)
37
+ return inlined
38
+ }
39
+
40
+ const warnNotInlined = (filename: string) =>
41
+ console.warn(`WARNING: asset not inlined: ${filename}`)
42
+
43
+ export function nativePlugin(): Plugin {
44
+ return {
45
+ name: 'vite:singlefile',
46
+ config: (config) => {
47
+ if (!config.build) config.build = {}
48
+ // Ensures that even very large assets are inlined in your JavaScript.
49
+ config.build.assetsInlineLimit = 100000000
50
+ // Avoid warnings about large chunks.
51
+ config.build.chunkSizeWarningLimit = 100000000
52
+ // Emit all CSS as a single file, which `vite-plugin-singlefile` can then inline.
53
+ config.build.cssCodeSplit = false
54
+ // Avoids the extra step of testing Brotli compression, which isn't really pertinent to a file served locally.
55
+ config.build.reportCompressedSize = false
56
+ // Subfolder bases are not supported, and shouldn't be needed because we're embedding everything.
57
+ config.base = undefined
58
+
59
+ if (!config.build.rollupOptions) config.build.rollupOptions = {}
60
+ if (!config.build.rollupOptions.output) config.build.rollupOptions.output = {}
61
+
62
+ const updateOutputOptions = (out: OutputOptions) => {
63
+ // Ensure that as many resources as possible are inlined.
64
+ out.inlineDynamicImports = true
65
+
66
+ // added by me (nate):
67
+ console.log('adding manualChunks = undefined')
68
+ out.manualChunks = undefined
69
+ }
70
+
71
+ if (Array.isArray(config.build.rollupOptions.output)) {
72
+ for (const o in config.build.rollupOptions.output)
73
+ updateOutputOptions(o as OutputOptions)
74
+ } else {
75
+ updateOutputOptions(config.build.rollupOptions.output as OutputOptions)
76
+ }
77
+ },
78
+
79
+ enforce: 'post',
80
+
81
+ generateBundle: (_, bundle) => {
82
+ const inlinePattern = []
83
+ const jsExtensionTest = /\.[mc]?js$/
84
+ const htmlFiles = Object.keys(bundle).filter((i) => i.endsWith('.html'))
85
+ const cssAssets = Object.keys(bundle).filter((i) => i.endsWith('.css'))
86
+ const jsAssets = Object.keys(bundle).filter((i) => jsExtensionTest.test(i))
87
+ const bundlesToDelete = [] as string[]
88
+
89
+ console.log('bundle', bundle)
90
+
91
+ // for (const name of htmlFiles) {
92
+ // const htmlChunk = bundle[name] as OutputAsset
93
+ // let replacedHtml = htmlChunk.source as string
94
+ // for (const jsName of jsAssets) {
95
+ // if (!inlinePattern.length || micromatch.isMatch(jsName, inlinePattern)) {
96
+ // const jsChunk = bundle[jsName] as OutputChunk
97
+ // if (jsChunk.code != null) {
98
+ // bundlesToDelete.push(jsName)
99
+ // replacedHtml = replaceScript(
100
+ // replacedHtml,
101
+ // jsChunk.fileName,
102
+ // jsChunk.code,
103
+ // false
104
+ // // removeViteModuleLoader
105
+ // )
106
+ // }
107
+ // } else {
108
+ // warnNotInlined(jsName)
109
+ // }
110
+ // }
111
+ // for (const cssName of cssAssets) {
112
+ // if (!inlinePattern.length || micromatch.isMatch(cssName, inlinePattern)) {
113
+ // const cssChunk = bundle[cssName] as OutputAsset
114
+ // bundlesToDelete.push(cssName)
115
+ // replacedHtml = replaceCss(
116
+ // replacedHtml,
117
+ // cssChunk.fileName,
118
+ // cssChunk.source as string
119
+ // )
120
+ // } else {
121
+ // warnNotInlined(cssName)
122
+ // }
123
+ // }
124
+ // htmlChunk.source = replacedHtml
125
+ // }
126
+
127
+ // if (deleteInlinedFiles) {
128
+ // for (const name of bundlesToDelete) {
129
+ // delete bundle[name]
130
+ // }
131
+ // }
132
+
133
+ // for (const name of Object.keys(bundle).filter(
134
+ // (i) => !jsExtensionTest.test(i) && !i.endsWith('.css') && !i.endsWith('.html')
135
+ // )) {
136
+ // warnNotInlined(name)
137
+ // }
138
+ },
139
+ }
140
+ }
141
+
142
+ // Optionally remove the Vite module loader since it's no longer needed because this plugin has inlined all code.
143
+ // This assumes that the Module Loader is (1) the FIRST function declared in the module, (2) an IIFE, (3) is minified,
144
+ // (4) is within a script with no unexpected attribute values, and (5) that the containing script is the first script
145
+ // tag that matches the above criteria. Changes to the SCRIPT tag especially could break this again in the future.
146
+ // Update example:
147
+ // https://github.com/richardtallent/vite-plugin-singlefile/issues/57#issuecomment-1263950209
148
+ const _removeViteModuleLoader = (html: string) =>
149
+ html.replace(
150
+ /(<script type="module" crossorigin>\s*)\(function\(\)\{[\s\S]*?\}\)\(\);/,
151
+ '<script type="module">\n'
152
+ )
package/types/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './plugin.js';
2
2
  export * from './extract.js';
3
+ export * from './native.js';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+ export declare function replaceScript(html: string, scriptFilename: string, scriptCode: string, removeViteModuleLoader?: boolean): string;
3
+ export declare function replaceCss(html: string, scriptFilename: string, scriptCode: string): string;
4
+ export declare function nativePlugin(): Plugin;
5
+ //# sourceMappingURL=native.d.ts.map