@tamagui/vite-plugin 1.0.1-beta.100
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 +18 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/plugin.js +92 -0
- package/dist/cjs/plugin.js.map +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/plugin.js +66 -0
- package/dist/esm/plugin.js.map +7 -0
- package/dist/jsx/index.js +2 -0
- package/dist/jsx/index.js.map +7 -0
- package/dist/jsx/plugin.js +66 -0
- package/dist/jsx/plugin.js.map +7 -0
- package/package.json +32 -0
- package/src/index.ts +1 -0
- package/src/plugin.ts +257 -0
- package/types/index.d.ts +2 -0
- package/types/index.d.ts.map +1 -0
- package/types/plugin.d.ts +4 -0
- package/types/plugin.d.ts.map +1 -0
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./plugin"), module.exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
|
|
20
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
21
|
+
var plugin_exports = {};
|
|
22
|
+
__export(plugin_exports, {
|
|
23
|
+
tamaguiPlugin: () => tamaguiPlugin
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
26
|
+
var import_vite_plugin_environment = __toESM(require("vite-plugin-environment"));
|
|
27
|
+
function tamaguiPlugin(options) {
|
|
28
|
+
return {
|
|
29
|
+
name: "tamagui",
|
|
30
|
+
enforce: "pre",
|
|
31
|
+
config(userConfig, env) {
|
|
32
|
+
return {
|
|
33
|
+
plugins: [(0, import_vite_plugin_environment.default)(["NODE_ENV", "TAMAGUI_TARGET"])],
|
|
34
|
+
esbuild: {
|
|
35
|
+
loader: "tsx"
|
|
36
|
+
},
|
|
37
|
+
define: {
|
|
38
|
+
"global.__x": {},
|
|
39
|
+
_frameTimestamp: void 0,
|
|
40
|
+
_WORKLET: false,
|
|
41
|
+
process: {
|
|
42
|
+
env: {
|
|
43
|
+
TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || "web",
|
|
44
|
+
NODE_ENV: process.env.NODE_ENV || env.mode
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
optimizeDeps: {
|
|
49
|
+
esbuildOptions: {
|
|
50
|
+
resolveExtensions: [
|
|
51
|
+
".web.js",
|
|
52
|
+
".web.ts",
|
|
53
|
+
".web.tsx",
|
|
54
|
+
".js",
|
|
55
|
+
".jsx",
|
|
56
|
+
".json",
|
|
57
|
+
".ts",
|
|
58
|
+
".tsx",
|
|
59
|
+
".mjs"
|
|
60
|
+
],
|
|
61
|
+
loader: {
|
|
62
|
+
".js": "jsx"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
resolve: {
|
|
67
|
+
extensions: [
|
|
68
|
+
".web.js",
|
|
69
|
+
".web.ts",
|
|
70
|
+
".web.tsx",
|
|
71
|
+
".js",
|
|
72
|
+
".jsx",
|
|
73
|
+
".json",
|
|
74
|
+
".ts",
|
|
75
|
+
".tsx",
|
|
76
|
+
".mjs"
|
|
77
|
+
],
|
|
78
|
+
alias: {
|
|
79
|
+
"react-native/Libraries/Renderer/shims/ReactFabric": "@tamagui/proxy-worm",
|
|
80
|
+
"react-native/Libraries/Utilities/codegenNativeComponent": "@tamagui/proxy-worm",
|
|
81
|
+
"react-native": "react-native-web"
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
89
|
+
0 && (module.exports = {
|
|
90
|
+
tamaguiPlugin
|
|
91
|
+
});
|
|
92
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/plugin.ts"],
|
|
4
|
+
"sourcesContent": ["import type { TamaguiOptions } from '@tamagui/static'\nimport type { Plugin } from 'vite'\nimport envPlugin from 'vite-plugin-environment'\n\nexport function tamaguiPlugin(options?: TamaguiOptions): Plugin {\n return {\n name: 'tamagui',\n enforce: 'pre',\n\n config(userConfig, env) {\n return {\n plugins: [envPlugin(['NODE_ENV', 'TAMAGUI_TARGET'])],\n esbuild: {\n loader: 'tsx',\n },\n define: {\n 'global.__x': {},\n _frameTimestamp: undefined,\n _WORKLET: false,\n process: {\n env: {\n TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || 'web',\n NODE_ENV: process.env.NODE_ENV || env.mode,\n },\n },\n },\n optimizeDeps: {\n esbuildOptions: {\n resolveExtensions: [\n '.web.js',\n '.web.ts',\n '.web.tsx',\n '.js',\n '.jsx',\n '.json',\n '.ts',\n '.tsx',\n '.mjs',\n ],\n loader: {\n '.js': 'jsx',\n },\n },\n },\n resolve: {\n // for once it extracts\n // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext'],\n extensions: [\n '.web.js',\n '.web.ts',\n '.web.tsx',\n '.js',\n '.jsx',\n '.json',\n '.ts',\n '.tsx',\n '.mjs',\n ],\n alias: {\n 'react-native/Libraries/Renderer/shims/ReactFabric': '@tamagui/proxy-worm',\n 'react-native/Libraries/Utilities/codegenNativeComponent': '@tamagui/proxy-worm',\n 'react-native': 'react-native-web',\n },\n },\n }\n },\n }\n}\n\n// fork from https://github.com/seek-oss/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts\n\n// import path from 'path'\n\n// import outdent from 'outdent'\n// import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'\n// import { normalizePath } from 'vite'\n\n// const styleUpdateEvent = (fileId: string) => `tamagui-style-update:${fileId}`\n\n// interface Options {\n// identifiers?: IdentifierOption\n// esbuildOptions?: CompileOptions['esbuildOptions']\n// }\n// export function vanillaExtractPlugin({ identifiers, esbuildOptions }: Options = {}): Plugin {\n// let config: ResolvedConfig\n// let server: ViteDevServer\n// let postCssConfig: PostCSSConfigResult | null\n// const cssMap = new Map<string, string>()\n\n// let virtualExt: string\n// let packageName: string\n\n// const getAbsoluteVirtualFileId = (source: string) => normalizePath(path.join(config.root, source))\n\n// return {\n// name: 'tamagui',\n// enforce: 'pre',\n// configureServer(_server) {\n// server = _server\n// },\n// config(_userConfig, env) {\n// const include = env.command === 'serve' ? ['@tamagui/css/injectStyles'] : []\n\n// return {\n// optimizeDeps: { include },\n// ssr: {\n// external: ['@tamagui/css', '@tamagui/css/fileScope', '@tamagui/css/adapter'],\n// },\n// }\n// },\n// async configResolved(resolvedConfig) {\n// config = resolvedConfig\n// packageName = getPackageInfo(config.root).name\n\n// if (config.command === 'serve') {\n// postCssConfig = await resolvePostcssConfig(config)\n// }\n\n// virtualExt = `.vanilla.${config.command === 'serve' ? 'js' : 'css'}`\n// },\n// resolveId(source) {\n// if (!source.endsWith(virtualExt)) {\n// return\n// }\n\n// // Absolute paths seem to occur often in monorepos, where files are\n// // imported from outside the config root.\n// const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source)\n\n// // There should always be an entry in the `cssMap` here.\n// // The only valid scenario for a missing one is if someone had written\n// // a file in their app using the .vanilla.js/.vanilla.css extension\n// if (cssMap.has(absoluteId)) {\n// return absoluteId\n// }\n// },\n// load(id) {\n// if (!cssMap.has(id)) {\n// return\n// }\n\n// const css = cssMap.get(id)\n\n// if (typeof css !== 'string') {\n// return\n// }\n\n// if (!server || server.config.isProduction) {\n// return css\n// }\n\n// return outdent`\n// import { injectStyles } from '@tamagui/css/injectStyles';\n\n// const inject = (css) => injectStyles({\n// fileScope: ${JSON.stringify({ filePath: id })},\n// css\n// });\n\n// inject(${JSON.stringify(css)});\n\n// import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {\n// inject(css);\n// });\n// `\n// },\n// async transform(code, id, ssrParam) {\n// if (!cssFileFilter.test(id)) {\n// return null\n// }\n\n// let ssr: boolean | undefined\n\n// if (typeof ssrParam === 'boolean') {\n// ssr = ssrParam\n// } else {\n// ssr = ssrParam?.ssr\n// }\n\n// const index = id.indexOf('?')\n// const validId = index === -1 ? id : id.substring(0, index)\n\n// if (ssr) {\n// return addFileScope({\n// source: code,\n// filePath: normalizePath(validId),\n// rootPath: config.root,\n// packageName,\n// })\n// }\n\n// const { source, watchFiles } = await compile({\n// filePath: validId,\n// cwd: config.root,\n// esbuildOptions,\n// })\n\n// for (const file of watchFiles) {\n// // In start mode, we need to prevent the file from rewatching itself.\n// // If it's a `build --watch`, it needs to watch everything.\n// if (config.command === 'build' || file !== id) {\n// this.addWatchFile(file)\n// }\n// }\n\n// const output = await processVanillaFile({\n// source,\n// filePath: validId,\n// identOption: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'),\n// serializeVirtualCssPath: async ({ fileScope, source }) => {\n// const rootRelativeId = `${fileScope.filePath}${virtualExt}`\n// const absoluteId = getAbsoluteVirtualFileId(rootRelativeId)\n\n// let cssSource = source\n\n// if (postCssConfig) {\n// const postCssResult = await (await import('postcss'))\n// .default(postCssConfig.plugins)\n// .process(source, {\n// ...postCssConfig.options,\n// from: undefined,\n// map: false,\n// })\n\n// cssSource = postCssResult.css\n// }\n\n// if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {\n// const { moduleGraph } = server\n// const module = moduleGraph.getModuleById(absoluteId)\n\n// if (module) {\n// moduleGraph.invalidateModule(module)\n// }\n\n// server.ws.send({\n// type: 'custom',\n// event: styleUpdateEvent(absoluteId),\n// data: cssSource,\n// })\n// }\n\n// cssMap.set(absoluteId, cssSource)\n\n// // We use the root relative id here to ensure file contents (content-hashes)\n// // are consistent across build machines\n// return `import \"${rootRelativeId}\";`\n// },\n// })\n\n// return {\n// code: output,\n// map: { mappings: '' },\n// }\n// },\n// }\n// }\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,qCAAsB;AAEf,uBAAuB,SAAkC;AAC9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,OAAO,YAAY,KAAK;AACtB,aAAO;AAAA,QACL,SAAS,CAAC,4CAAU,CAAC,YAAY,gBAAgB,CAAC,CAAC;AAAA,QACnD,SAAS;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,QACA,QAAQ;AAAA,UACN,cAAc,CAAC;AAAA,UACf,iBAAiB;AAAA,UACjB,UAAU;AAAA,UACV,SAAS;AAAA,YACP,KAAK;AAAA,cACH,gBAAgB,QAAQ,IAAI,kBAAkB;AAAA,cAC9C,UAAU,QAAQ,IAAI,YAAY,IAAI;AAAA,YACxC;AAAA,UACF;AAAA,QACF;AAAA,QACA,cAAc;AAAA,UACZ,gBAAgB;AAAA,YACd,mBAAmB;AAAA,cACjB;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YACA,QAAQ;AAAA,cACN,OAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAAA,QACA,SAAS;AAAA,UAGP,YAAY;AAAA,YACV;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UACA,OAAO;AAAA,YACL,qDAAqD;AAAA,YACrD,2DAA2D;AAAA,YAC3D,gBAAgB;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import envPlugin from "vite-plugin-environment";
|
|
2
|
+
function tamaguiPlugin(options) {
|
|
3
|
+
return {
|
|
4
|
+
name: "tamagui",
|
|
5
|
+
enforce: "pre",
|
|
6
|
+
config(userConfig, env) {
|
|
7
|
+
return {
|
|
8
|
+
plugins: [envPlugin(["NODE_ENV", "TAMAGUI_TARGET"])],
|
|
9
|
+
esbuild: {
|
|
10
|
+
loader: "tsx"
|
|
11
|
+
},
|
|
12
|
+
define: {
|
|
13
|
+
"global.__x": {},
|
|
14
|
+
_frameTimestamp: void 0,
|
|
15
|
+
_WORKLET: false,
|
|
16
|
+
process: {
|
|
17
|
+
env: {
|
|
18
|
+
TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || "web",
|
|
19
|
+
NODE_ENV: process.env.NODE_ENV || env.mode
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
optimizeDeps: {
|
|
24
|
+
esbuildOptions: {
|
|
25
|
+
resolveExtensions: [
|
|
26
|
+
".web.js",
|
|
27
|
+
".web.ts",
|
|
28
|
+
".web.tsx",
|
|
29
|
+
".js",
|
|
30
|
+
".jsx",
|
|
31
|
+
".json",
|
|
32
|
+
".ts",
|
|
33
|
+
".tsx",
|
|
34
|
+
".mjs"
|
|
35
|
+
],
|
|
36
|
+
loader: {
|
|
37
|
+
".js": "jsx"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
resolve: {
|
|
42
|
+
extensions: [
|
|
43
|
+
".web.js",
|
|
44
|
+
".web.ts",
|
|
45
|
+
".web.tsx",
|
|
46
|
+
".js",
|
|
47
|
+
".jsx",
|
|
48
|
+
".json",
|
|
49
|
+
".ts",
|
|
50
|
+
".tsx",
|
|
51
|
+
".mjs"
|
|
52
|
+
],
|
|
53
|
+
alias: {
|
|
54
|
+
"react-native/Libraries/Renderer/shims/ReactFabric": "@tamagui/proxy-worm",
|
|
55
|
+
"react-native/Libraries/Utilities/codegenNativeComponent": "@tamagui/proxy-worm",
|
|
56
|
+
"react-native": "react-native-web"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
tamaguiPlugin
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/plugin.ts"],
|
|
4
|
+
"sourcesContent": ["import type { TamaguiOptions } from '@tamagui/static'\nimport type { Plugin } from 'vite'\nimport envPlugin from 'vite-plugin-environment'\n\nexport function tamaguiPlugin(options?: TamaguiOptions): Plugin {\n return {\n name: 'tamagui',\n enforce: 'pre',\n\n config(userConfig, env) {\n return {\n plugins: [envPlugin(['NODE_ENV', 'TAMAGUI_TARGET'])],\n esbuild: {\n loader: 'tsx',\n },\n define: {\n 'global.__x': {},\n _frameTimestamp: undefined,\n _WORKLET: false,\n process: {\n env: {\n TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || 'web',\n NODE_ENV: process.env.NODE_ENV || env.mode,\n },\n },\n },\n optimizeDeps: {\n esbuildOptions: {\n resolveExtensions: [\n '.web.js',\n '.web.ts',\n '.web.tsx',\n '.js',\n '.jsx',\n '.json',\n '.ts',\n '.tsx',\n '.mjs',\n ],\n loader: {\n '.js': 'jsx',\n },\n },\n },\n resolve: {\n // for once it extracts\n // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext'],\n extensions: [\n '.web.js',\n '.web.ts',\n '.web.tsx',\n '.js',\n '.jsx',\n '.json',\n '.ts',\n '.tsx',\n '.mjs',\n ],\n alias: {\n 'react-native/Libraries/Renderer/shims/ReactFabric': '@tamagui/proxy-worm',\n 'react-native/Libraries/Utilities/codegenNativeComponent': '@tamagui/proxy-worm',\n 'react-native': 'react-native-web',\n },\n },\n }\n },\n }\n}\n\n// fork from https://github.com/seek-oss/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts\n\n// import path from 'path'\n\n// import outdent from 'outdent'\n// import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'\n// import { normalizePath } from 'vite'\n\n// const styleUpdateEvent = (fileId: string) => `tamagui-style-update:${fileId}`\n\n// interface Options {\n// identifiers?: IdentifierOption\n// esbuildOptions?: CompileOptions['esbuildOptions']\n// }\n// export function vanillaExtractPlugin({ identifiers, esbuildOptions }: Options = {}): Plugin {\n// let config: ResolvedConfig\n// let server: ViteDevServer\n// let postCssConfig: PostCSSConfigResult | null\n// const cssMap = new Map<string, string>()\n\n// let virtualExt: string\n// let packageName: string\n\n// const getAbsoluteVirtualFileId = (source: string) => normalizePath(path.join(config.root, source))\n\n// return {\n// name: 'tamagui',\n// enforce: 'pre',\n// configureServer(_server) {\n// server = _server\n// },\n// config(_userConfig, env) {\n// const include = env.command === 'serve' ? ['@tamagui/css/injectStyles'] : []\n\n// return {\n// optimizeDeps: { include },\n// ssr: {\n// external: ['@tamagui/css', '@tamagui/css/fileScope', '@tamagui/css/adapter'],\n// },\n// }\n// },\n// async configResolved(resolvedConfig) {\n// config = resolvedConfig\n// packageName = getPackageInfo(config.root).name\n\n// if (config.command === 'serve') {\n// postCssConfig = await resolvePostcssConfig(config)\n// }\n\n// virtualExt = `.vanilla.${config.command === 'serve' ? 'js' : 'css'}`\n// },\n// resolveId(source) {\n// if (!source.endsWith(virtualExt)) {\n// return\n// }\n\n// // Absolute paths seem to occur often in monorepos, where files are\n// // imported from outside the config root.\n// const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source)\n\n// // There should always be an entry in the `cssMap` here.\n// // The only valid scenario for a missing one is if someone had written\n// // a file in their app using the .vanilla.js/.vanilla.css extension\n// if (cssMap.has(absoluteId)) {\n// return absoluteId\n// }\n// },\n// load(id) {\n// if (!cssMap.has(id)) {\n// return\n// }\n\n// const css = cssMap.get(id)\n\n// if (typeof css !== 'string') {\n// return\n// }\n\n// if (!server || server.config.isProduction) {\n// return css\n// }\n\n// return outdent`\n// import { injectStyles } from '@tamagui/css/injectStyles';\n\n// const inject = (css) => injectStyles({\n// fileScope: ${JSON.stringify({ filePath: id })},\n// css\n// });\n\n// inject(${JSON.stringify(css)});\n\n// import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {\n// inject(css);\n// });\n// `\n// },\n// async transform(code, id, ssrParam) {\n// if (!cssFileFilter.test(id)) {\n// return null\n// }\n\n// let ssr: boolean | undefined\n\n// if (typeof ssrParam === 'boolean') {\n// ssr = ssrParam\n// } else {\n// ssr = ssrParam?.ssr\n// }\n\n// const index = id.indexOf('?')\n// const validId = index === -1 ? id : id.substring(0, index)\n\n// if (ssr) {\n// return addFileScope({\n// source: code,\n// filePath: normalizePath(validId),\n// rootPath: config.root,\n// packageName,\n// })\n// }\n\n// const { source, watchFiles } = await compile({\n// filePath: validId,\n// cwd: config.root,\n// esbuildOptions,\n// })\n\n// for (const file of watchFiles) {\n// // In start mode, we need to prevent the file from rewatching itself.\n// // If it's a `build --watch`, it needs to watch everything.\n// if (config.command === 'build' || file !== id) {\n// this.addWatchFile(file)\n// }\n// }\n\n// const output = await processVanillaFile({\n// source,\n// filePath: validId,\n// identOption: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'),\n// serializeVirtualCssPath: async ({ fileScope, source }) => {\n// const rootRelativeId = `${fileScope.filePath}${virtualExt}`\n// const absoluteId = getAbsoluteVirtualFileId(rootRelativeId)\n\n// let cssSource = source\n\n// if (postCssConfig) {\n// const postCssResult = await (await import('postcss'))\n// .default(postCssConfig.plugins)\n// .process(source, {\n// ...postCssConfig.options,\n// from: undefined,\n// map: false,\n// })\n\n// cssSource = postCssResult.css\n// }\n\n// if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {\n// const { moduleGraph } = server\n// const module = moduleGraph.getModuleById(absoluteId)\n\n// if (module) {\n// moduleGraph.invalidateModule(module)\n// }\n\n// server.ws.send({\n// type: 'custom',\n// event: styleUpdateEvent(absoluteId),\n// data: cssSource,\n// })\n// }\n\n// cssMap.set(absoluteId, cssSource)\n\n// // We use the root relative id here to ensure file contents (content-hashes)\n// // are consistent across build machines\n// return `import \"${rootRelativeId}\";`\n// },\n// })\n\n// return {\n// code: output,\n// map: { mappings: '' },\n// }\n// },\n// }\n// }\n"],
|
|
5
|
+
"mappings": "AAEA;AAEO,uBAAuB,SAAkC;AAC9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,OAAO,YAAY,KAAK;AACtB,aAAO;AAAA,QACL,SAAS,CAAC,UAAU,CAAC,YAAY,gBAAgB,CAAC,CAAC;AAAA,QACnD,SAAS;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,QACA,QAAQ;AAAA,UACN,cAAc,CAAC;AAAA,UACf,iBAAiB;AAAA,UACjB,UAAU;AAAA,UACV,SAAS;AAAA,YACP,KAAK;AAAA,cACH,gBAAgB,QAAQ,IAAI,kBAAkB;AAAA,cAC9C,UAAU,QAAQ,IAAI,YAAY,IAAI;AAAA,YACxC;AAAA,UACF;AAAA,QACF;AAAA,QACA,cAAc;AAAA,UACZ,gBAAgB;AAAA,YACd,mBAAmB;AAAA,cACjB;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YACA,QAAQ;AAAA,cACN,OAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAAA,QACA,SAAS;AAAA,UAGP,YAAY;AAAA,YACV;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UACA,OAAO;AAAA,YACL,qDAAqD;AAAA,YACrD,2DAA2D;AAAA,YAC3D,gBAAgB;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import envPlugin from "vite-plugin-environment";
|
|
2
|
+
function tamaguiPlugin(options) {
|
|
3
|
+
return {
|
|
4
|
+
name: "tamagui",
|
|
5
|
+
enforce: "pre",
|
|
6
|
+
config(userConfig, env) {
|
|
7
|
+
return {
|
|
8
|
+
plugins: [envPlugin(["NODE_ENV", "TAMAGUI_TARGET"])],
|
|
9
|
+
esbuild: {
|
|
10
|
+
loader: "tsx"
|
|
11
|
+
},
|
|
12
|
+
define: {
|
|
13
|
+
"global.__x": {},
|
|
14
|
+
_frameTimestamp: void 0,
|
|
15
|
+
_WORKLET: false,
|
|
16
|
+
process: {
|
|
17
|
+
env: {
|
|
18
|
+
TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || "web",
|
|
19
|
+
NODE_ENV: process.env.NODE_ENV || env.mode
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
optimizeDeps: {
|
|
24
|
+
esbuildOptions: {
|
|
25
|
+
resolveExtensions: [
|
|
26
|
+
".web.js",
|
|
27
|
+
".web.ts",
|
|
28
|
+
".web.tsx",
|
|
29
|
+
".js",
|
|
30
|
+
".jsx",
|
|
31
|
+
".json",
|
|
32
|
+
".ts",
|
|
33
|
+
".tsx",
|
|
34
|
+
".mjs"
|
|
35
|
+
],
|
|
36
|
+
loader: {
|
|
37
|
+
".js": "jsx"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
resolve: {
|
|
42
|
+
extensions: [
|
|
43
|
+
".web.js",
|
|
44
|
+
".web.ts",
|
|
45
|
+
".web.tsx",
|
|
46
|
+
".js",
|
|
47
|
+
".jsx",
|
|
48
|
+
".json",
|
|
49
|
+
".ts",
|
|
50
|
+
".tsx",
|
|
51
|
+
".mjs"
|
|
52
|
+
],
|
|
53
|
+
alias: {
|
|
54
|
+
"react-native/Libraries/Renderer/shims/ReactFabric": "@tamagui/proxy-worm",
|
|
55
|
+
"react-native/Libraries/Utilities/codegenNativeComponent": "@tamagui/proxy-worm",
|
|
56
|
+
"react-native": "react-native-web"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export {
|
|
64
|
+
tamaguiPlugin
|
|
65
|
+
};
|
|
66
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/plugin.ts"],
|
|
4
|
+
"sourcesContent": ["import type { TamaguiOptions } from '@tamagui/static'\nimport type { Plugin } from 'vite'\nimport envPlugin from 'vite-plugin-environment'\n\nexport function tamaguiPlugin(options?: TamaguiOptions): Plugin {\n return {\n name: 'tamagui',\n enforce: 'pre',\n\n config(userConfig, env) {\n return {\n plugins: [envPlugin(['NODE_ENV', 'TAMAGUI_TARGET'])],\n esbuild: {\n loader: 'tsx',\n },\n define: {\n 'global.__x': {},\n _frameTimestamp: undefined,\n _WORKLET: false,\n process: {\n env: {\n TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || 'web',\n NODE_ENV: process.env.NODE_ENV || env.mode,\n },\n },\n },\n optimizeDeps: {\n esbuildOptions: {\n resolveExtensions: [\n '.web.js',\n '.web.ts',\n '.web.tsx',\n '.js',\n '.jsx',\n '.json',\n '.ts',\n '.tsx',\n '.mjs',\n ],\n loader: {\n '.js': 'jsx',\n },\n },\n },\n resolve: {\n // for once it extracts\n // mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext'],\n extensions: [\n '.web.js',\n '.web.ts',\n '.web.tsx',\n '.js',\n '.jsx',\n '.json',\n '.ts',\n '.tsx',\n '.mjs',\n ],\n alias: {\n 'react-native/Libraries/Renderer/shims/ReactFabric': '@tamagui/proxy-worm',\n 'react-native/Libraries/Utilities/codegenNativeComponent': '@tamagui/proxy-worm',\n 'react-native': 'react-native-web',\n },\n },\n }\n },\n }\n}\n\n// fork from https://github.com/seek-oss/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts\n\n// import path from 'path'\n\n// import outdent from 'outdent'\n// import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'\n// import { normalizePath } from 'vite'\n\n// const styleUpdateEvent = (fileId: string) => `tamagui-style-update:${fileId}`\n\n// interface Options {\n// identifiers?: IdentifierOption\n// esbuildOptions?: CompileOptions['esbuildOptions']\n// }\n// export function vanillaExtractPlugin({ identifiers, esbuildOptions }: Options = {}): Plugin {\n// let config: ResolvedConfig\n// let server: ViteDevServer\n// let postCssConfig: PostCSSConfigResult | null\n// const cssMap = new Map<string, string>()\n\n// let virtualExt: string\n// let packageName: string\n\n// const getAbsoluteVirtualFileId = (source: string) => normalizePath(path.join(config.root, source))\n\n// return {\n// name: 'tamagui',\n// enforce: 'pre',\n// configureServer(_server) {\n// server = _server\n// },\n// config(_userConfig, env) {\n// const include = env.command === 'serve' ? ['@tamagui/css/injectStyles'] : []\n\n// return {\n// optimizeDeps: { include },\n// ssr: {\n// external: ['@tamagui/css', '@tamagui/css/fileScope', '@tamagui/css/adapter'],\n// },\n// }\n// },\n// async configResolved(resolvedConfig) {\n// config = resolvedConfig\n// packageName = getPackageInfo(config.root).name\n\n// if (config.command === 'serve') {\n// postCssConfig = await resolvePostcssConfig(config)\n// }\n\n// virtualExt = `.vanilla.${config.command === 'serve' ? 'js' : 'css'}`\n// },\n// resolveId(source) {\n// if (!source.endsWith(virtualExt)) {\n// return\n// }\n\n// // Absolute paths seem to occur often in monorepos, where files are\n// // imported from outside the config root.\n// const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source)\n\n// // There should always be an entry in the `cssMap` here.\n// // The only valid scenario for a missing one is if someone had written\n// // a file in their app using the .vanilla.js/.vanilla.css extension\n// if (cssMap.has(absoluteId)) {\n// return absoluteId\n// }\n// },\n// load(id) {\n// if (!cssMap.has(id)) {\n// return\n// }\n\n// const css = cssMap.get(id)\n\n// if (typeof css !== 'string') {\n// return\n// }\n\n// if (!server || server.config.isProduction) {\n// return css\n// }\n\n// return outdent`\n// import { injectStyles } from '@tamagui/css/injectStyles';\n\n// const inject = (css) => injectStyles({\n// fileScope: ${JSON.stringify({ filePath: id })},\n// css\n// });\n\n// inject(${JSON.stringify(css)});\n\n// import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {\n// inject(css);\n// });\n// `\n// },\n// async transform(code, id, ssrParam) {\n// if (!cssFileFilter.test(id)) {\n// return null\n// }\n\n// let ssr: boolean | undefined\n\n// if (typeof ssrParam === 'boolean') {\n// ssr = ssrParam\n// } else {\n// ssr = ssrParam?.ssr\n// }\n\n// const index = id.indexOf('?')\n// const validId = index === -1 ? id : id.substring(0, index)\n\n// if (ssr) {\n// return addFileScope({\n// source: code,\n// filePath: normalizePath(validId),\n// rootPath: config.root,\n// packageName,\n// })\n// }\n\n// const { source, watchFiles } = await compile({\n// filePath: validId,\n// cwd: config.root,\n// esbuildOptions,\n// })\n\n// for (const file of watchFiles) {\n// // In start mode, we need to prevent the file from rewatching itself.\n// // If it's a `build --watch`, it needs to watch everything.\n// if (config.command === 'build' || file !== id) {\n// this.addWatchFile(file)\n// }\n// }\n\n// const output = await processVanillaFile({\n// source,\n// filePath: validId,\n// identOption: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'),\n// serializeVirtualCssPath: async ({ fileScope, source }) => {\n// const rootRelativeId = `${fileScope.filePath}${virtualExt}`\n// const absoluteId = getAbsoluteVirtualFileId(rootRelativeId)\n\n// let cssSource = source\n\n// if (postCssConfig) {\n// const postCssResult = await (await import('postcss'))\n// .default(postCssConfig.plugins)\n// .process(source, {\n// ...postCssConfig.options,\n// from: undefined,\n// map: false,\n// })\n\n// cssSource = postCssResult.css\n// }\n\n// if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {\n// const { moduleGraph } = server\n// const module = moduleGraph.getModuleById(absoluteId)\n\n// if (module) {\n// moduleGraph.invalidateModule(module)\n// }\n\n// server.ws.send({\n// type: 'custom',\n// event: styleUpdateEvent(absoluteId),\n// data: cssSource,\n// })\n// }\n\n// cssMap.set(absoluteId, cssSource)\n\n// // We use the root relative id here to ensure file contents (content-hashes)\n// // are consistent across build machines\n// return `import \"${rootRelativeId}\";`\n// },\n// })\n\n// return {\n// code: output,\n// map: { mappings: '' },\n// }\n// },\n// }\n// }\n"],
|
|
5
|
+
"mappings": "AAEA;AAEO,uBAAuB,SAAkC;AAC9D,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,OAAO,YAAY,KAAK;AACtB,aAAO;AAAA,QACL,SAAS,CAAC,UAAU,CAAC,YAAY,gBAAgB,CAAC,CAAC;AAAA,QACnD,SAAS;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,QACA,QAAQ;AAAA,UACN,cAAc,CAAC;AAAA,UACf,iBAAiB;AAAA,UACjB,UAAU;AAAA,UACV,SAAS;AAAA,YACP,KAAK;AAAA,cACH,gBAAgB,QAAQ,IAAI,kBAAkB;AAAA,cAC9C,UAAU,QAAQ,IAAI,YAAY,IAAI;AAAA,YACxC;AAAA,UACF;AAAA,QACF;AAAA,QACA,cAAc;AAAA,UACZ,gBAAgB;AAAA,YACd,mBAAmB;AAAA,cACjB;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,YACF;AAAA,YACA,QAAQ;AAAA,cACN,OAAO;AAAA,YACT;AAAA,UACF;AAAA,QACF;AAAA,QACA,SAAS;AAAA,UAGP,YAAY;AAAA,YACV;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,UACA,OAAO;AAAA,YACL,qDAAqD;AAAA,YACrD,2DAA2D;AAAA,YAC3D,gBAAgB;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tamagui/vite-plugin",
|
|
3
|
+
"version": "1.0.1-beta.100",
|
|
4
|
+
"types": "./types/index.d.ts",
|
|
5
|
+
"main": "dist/cjs",
|
|
6
|
+
"module": "dist/esm",
|
|
7
|
+
"module:jsx": "dist/jsx",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"files": [
|
|
10
|
+
"src",
|
|
11
|
+
"types",
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tamagui-build",
|
|
16
|
+
"watch": "tamagui-build --watch",
|
|
17
|
+
"clean": "tamagui-build clean",
|
|
18
|
+
"clean:build": "tamagui-build clean:build"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@tamagui/proxy-worm": "^1.0.1-beta.100",
|
|
22
|
+
"fs-extra": "^10.1.0",
|
|
23
|
+
"lodash": "^4.17.21"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@tamagui/build": "^1.0.1-beta.100",
|
|
27
|
+
"vite-plugin-environment": "^1.1.1"
|
|
28
|
+
},
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './plugin'
|
package/src/plugin.ts
ADDED
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
import type { TamaguiOptions } from '@tamagui/static'
|
|
2
|
+
import type { Plugin } from 'vite'
|
|
3
|
+
import envPlugin from 'vite-plugin-environment'
|
|
4
|
+
|
|
5
|
+
export function tamaguiPlugin(options?: TamaguiOptions): Plugin {
|
|
6
|
+
return {
|
|
7
|
+
name: 'tamagui',
|
|
8
|
+
enforce: 'pre',
|
|
9
|
+
|
|
10
|
+
config(userConfig, env) {
|
|
11
|
+
return {
|
|
12
|
+
plugins: [envPlugin(['NODE_ENV', 'TAMAGUI_TARGET'])],
|
|
13
|
+
esbuild: {
|
|
14
|
+
loader: 'tsx',
|
|
15
|
+
},
|
|
16
|
+
define: {
|
|
17
|
+
'global.__x': {},
|
|
18
|
+
_frameTimestamp: undefined,
|
|
19
|
+
_WORKLET: false,
|
|
20
|
+
process: {
|
|
21
|
+
env: {
|
|
22
|
+
TAMAGUI_TARGET: process.env.TAMAGUI_TARGET || 'web',
|
|
23
|
+
NODE_ENV: process.env.NODE_ENV || env.mode,
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
optimizeDeps: {
|
|
28
|
+
esbuildOptions: {
|
|
29
|
+
resolveExtensions: [
|
|
30
|
+
'.web.js',
|
|
31
|
+
'.web.ts',
|
|
32
|
+
'.web.tsx',
|
|
33
|
+
'.js',
|
|
34
|
+
'.jsx',
|
|
35
|
+
'.json',
|
|
36
|
+
'.ts',
|
|
37
|
+
'.tsx',
|
|
38
|
+
'.mjs',
|
|
39
|
+
],
|
|
40
|
+
loader: {
|
|
41
|
+
'.js': 'jsx',
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
resolve: {
|
|
46
|
+
// for once it extracts
|
|
47
|
+
// mainFields: ['module:jsx', 'module', 'jsnext:main', 'jsnext'],
|
|
48
|
+
extensions: [
|
|
49
|
+
'.web.js',
|
|
50
|
+
'.web.ts',
|
|
51
|
+
'.web.tsx',
|
|
52
|
+
'.js',
|
|
53
|
+
'.jsx',
|
|
54
|
+
'.json',
|
|
55
|
+
'.ts',
|
|
56
|
+
'.tsx',
|
|
57
|
+
'.mjs',
|
|
58
|
+
],
|
|
59
|
+
alias: {
|
|
60
|
+
'react-native/Libraries/Renderer/shims/ReactFabric': '@tamagui/proxy-worm',
|
|
61
|
+
'react-native/Libraries/Utilities/codegenNativeComponent': '@tamagui/proxy-worm',
|
|
62
|
+
'react-native': 'react-native-web',
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// fork from https://github.com/seek-oss/vanilla-extract/blob/master/packages/vite-plugin/src/index.ts
|
|
71
|
+
|
|
72
|
+
// import path from 'path'
|
|
73
|
+
|
|
74
|
+
// import outdent from 'outdent'
|
|
75
|
+
// import type { Plugin, ResolvedConfig, ViteDevServer } from 'vite'
|
|
76
|
+
// import { normalizePath } from 'vite'
|
|
77
|
+
|
|
78
|
+
// const styleUpdateEvent = (fileId: string) => `tamagui-style-update:${fileId}`
|
|
79
|
+
|
|
80
|
+
// interface Options {
|
|
81
|
+
// identifiers?: IdentifierOption
|
|
82
|
+
// esbuildOptions?: CompileOptions['esbuildOptions']
|
|
83
|
+
// }
|
|
84
|
+
// export function vanillaExtractPlugin({ identifiers, esbuildOptions }: Options = {}): Plugin {
|
|
85
|
+
// let config: ResolvedConfig
|
|
86
|
+
// let server: ViteDevServer
|
|
87
|
+
// let postCssConfig: PostCSSConfigResult | null
|
|
88
|
+
// const cssMap = new Map<string, string>()
|
|
89
|
+
|
|
90
|
+
// let virtualExt: string
|
|
91
|
+
// let packageName: string
|
|
92
|
+
|
|
93
|
+
// const getAbsoluteVirtualFileId = (source: string) => normalizePath(path.join(config.root, source))
|
|
94
|
+
|
|
95
|
+
// return {
|
|
96
|
+
// name: 'tamagui',
|
|
97
|
+
// enforce: 'pre',
|
|
98
|
+
// configureServer(_server) {
|
|
99
|
+
// server = _server
|
|
100
|
+
// },
|
|
101
|
+
// config(_userConfig, env) {
|
|
102
|
+
// const include = env.command === 'serve' ? ['@tamagui/css/injectStyles'] : []
|
|
103
|
+
|
|
104
|
+
// return {
|
|
105
|
+
// optimizeDeps: { include },
|
|
106
|
+
// ssr: {
|
|
107
|
+
// external: ['@tamagui/css', '@tamagui/css/fileScope', '@tamagui/css/adapter'],
|
|
108
|
+
// },
|
|
109
|
+
// }
|
|
110
|
+
// },
|
|
111
|
+
// async configResolved(resolvedConfig) {
|
|
112
|
+
// config = resolvedConfig
|
|
113
|
+
// packageName = getPackageInfo(config.root).name
|
|
114
|
+
|
|
115
|
+
// if (config.command === 'serve') {
|
|
116
|
+
// postCssConfig = await resolvePostcssConfig(config)
|
|
117
|
+
// }
|
|
118
|
+
|
|
119
|
+
// virtualExt = `.vanilla.${config.command === 'serve' ? 'js' : 'css'}`
|
|
120
|
+
// },
|
|
121
|
+
// resolveId(source) {
|
|
122
|
+
// if (!source.endsWith(virtualExt)) {
|
|
123
|
+
// return
|
|
124
|
+
// }
|
|
125
|
+
|
|
126
|
+
// // Absolute paths seem to occur often in monorepos, where files are
|
|
127
|
+
// // imported from outside the config root.
|
|
128
|
+
// const absoluteId = source.startsWith(config.root) ? source : getAbsoluteVirtualFileId(source)
|
|
129
|
+
|
|
130
|
+
// // There should always be an entry in the `cssMap` here.
|
|
131
|
+
// // The only valid scenario for a missing one is if someone had written
|
|
132
|
+
// // a file in their app using the .vanilla.js/.vanilla.css extension
|
|
133
|
+
// if (cssMap.has(absoluteId)) {
|
|
134
|
+
// return absoluteId
|
|
135
|
+
// }
|
|
136
|
+
// },
|
|
137
|
+
// load(id) {
|
|
138
|
+
// if (!cssMap.has(id)) {
|
|
139
|
+
// return
|
|
140
|
+
// }
|
|
141
|
+
|
|
142
|
+
// const css = cssMap.get(id)
|
|
143
|
+
|
|
144
|
+
// if (typeof css !== 'string') {
|
|
145
|
+
// return
|
|
146
|
+
// }
|
|
147
|
+
|
|
148
|
+
// if (!server || server.config.isProduction) {
|
|
149
|
+
// return css
|
|
150
|
+
// }
|
|
151
|
+
|
|
152
|
+
// return outdent`
|
|
153
|
+
// import { injectStyles } from '@tamagui/css/injectStyles';
|
|
154
|
+
|
|
155
|
+
// const inject = (css) => injectStyles({
|
|
156
|
+
// fileScope: ${JSON.stringify({ filePath: id })},
|
|
157
|
+
// css
|
|
158
|
+
// });
|
|
159
|
+
|
|
160
|
+
// inject(${JSON.stringify(css)});
|
|
161
|
+
|
|
162
|
+
// import.meta.hot.on('${styleUpdateEvent(id)}', (css) => {
|
|
163
|
+
// inject(css);
|
|
164
|
+
// });
|
|
165
|
+
// `
|
|
166
|
+
// },
|
|
167
|
+
// async transform(code, id, ssrParam) {
|
|
168
|
+
// if (!cssFileFilter.test(id)) {
|
|
169
|
+
// return null
|
|
170
|
+
// }
|
|
171
|
+
|
|
172
|
+
// let ssr: boolean | undefined
|
|
173
|
+
|
|
174
|
+
// if (typeof ssrParam === 'boolean') {
|
|
175
|
+
// ssr = ssrParam
|
|
176
|
+
// } else {
|
|
177
|
+
// ssr = ssrParam?.ssr
|
|
178
|
+
// }
|
|
179
|
+
|
|
180
|
+
// const index = id.indexOf('?')
|
|
181
|
+
// const validId = index === -1 ? id : id.substring(0, index)
|
|
182
|
+
|
|
183
|
+
// if (ssr) {
|
|
184
|
+
// return addFileScope({
|
|
185
|
+
// source: code,
|
|
186
|
+
// filePath: normalizePath(validId),
|
|
187
|
+
// rootPath: config.root,
|
|
188
|
+
// packageName,
|
|
189
|
+
// })
|
|
190
|
+
// }
|
|
191
|
+
|
|
192
|
+
// const { source, watchFiles } = await compile({
|
|
193
|
+
// filePath: validId,
|
|
194
|
+
// cwd: config.root,
|
|
195
|
+
// esbuildOptions,
|
|
196
|
+
// })
|
|
197
|
+
|
|
198
|
+
// for (const file of watchFiles) {
|
|
199
|
+
// // In start mode, we need to prevent the file from rewatching itself.
|
|
200
|
+
// // If it's a `build --watch`, it needs to watch everything.
|
|
201
|
+
// if (config.command === 'build' || file !== id) {
|
|
202
|
+
// this.addWatchFile(file)
|
|
203
|
+
// }
|
|
204
|
+
// }
|
|
205
|
+
|
|
206
|
+
// const output = await processVanillaFile({
|
|
207
|
+
// source,
|
|
208
|
+
// filePath: validId,
|
|
209
|
+
// identOption: identifiers ?? (config.mode === 'production' ? 'short' : 'debug'),
|
|
210
|
+
// serializeVirtualCssPath: async ({ fileScope, source }) => {
|
|
211
|
+
// const rootRelativeId = `${fileScope.filePath}${virtualExt}`
|
|
212
|
+
// const absoluteId = getAbsoluteVirtualFileId(rootRelativeId)
|
|
213
|
+
|
|
214
|
+
// let cssSource = source
|
|
215
|
+
|
|
216
|
+
// if (postCssConfig) {
|
|
217
|
+
// const postCssResult = await (await import('postcss'))
|
|
218
|
+
// .default(postCssConfig.plugins)
|
|
219
|
+
// .process(source, {
|
|
220
|
+
// ...postCssConfig.options,
|
|
221
|
+
// from: undefined,
|
|
222
|
+
// map: false,
|
|
223
|
+
// })
|
|
224
|
+
|
|
225
|
+
// cssSource = postCssResult.css
|
|
226
|
+
// }
|
|
227
|
+
|
|
228
|
+
// if (server && cssMap.has(absoluteId) && cssMap.get(absoluteId) !== source) {
|
|
229
|
+
// const { moduleGraph } = server
|
|
230
|
+
// const module = moduleGraph.getModuleById(absoluteId)
|
|
231
|
+
|
|
232
|
+
// if (module) {
|
|
233
|
+
// moduleGraph.invalidateModule(module)
|
|
234
|
+
// }
|
|
235
|
+
|
|
236
|
+
// server.ws.send({
|
|
237
|
+
// type: 'custom',
|
|
238
|
+
// event: styleUpdateEvent(absoluteId),
|
|
239
|
+
// data: cssSource,
|
|
240
|
+
// })
|
|
241
|
+
// }
|
|
242
|
+
|
|
243
|
+
// cssMap.set(absoluteId, cssSource)
|
|
244
|
+
|
|
245
|
+
// // We use the root relative id here to ensure file contents (content-hashes)
|
|
246
|
+
// // are consistent across build machines
|
|
247
|
+
// return `import "${rootRelativeId}";`
|
|
248
|
+
// },
|
|
249
|
+
// })
|
|
250
|
+
|
|
251
|
+
// return {
|
|
252
|
+
// code: output,
|
|
253
|
+
// map: { mappings: '' },
|
|
254
|
+
// }
|
|
255
|
+
// },
|
|
256
|
+
// }
|
|
257
|
+
// }
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAA;AAGlC,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,MAAM,CA+D9D"}
|