tamagui-loader 1.0.0-beta.8 → 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/css.js CHANGED
@@ -16,7 +16,6 @@ var __spreadValues = (a, b) => {
16
16
  }
17
17
  return a;
18
18
  };
19
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
20
19
  var __export = (target, all) => {
21
20
  for (var name in all)
22
21
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -39,7 +38,7 @@ __export(css_exports, {
39
38
  module.exports = __toCommonJS(css_exports);
40
39
  const extractedInfoByFile = /* @__PURE__ */ new Map();
41
40
  const stylePathToFilePath = /* @__PURE__ */ new Map();
42
- function loader(source) {
41
+ function loader() {
43
42
  this.async();
44
43
  const options = __spreadValues({}, this.getOptions());
45
44
  const sourcePath = `${this.resourcePath}`;
@@ -54,12 +53,11 @@ function loader(source) {
54
53
  } else if (options.cssData) {
55
54
  out = Buffer.from(options.cssData, "base64").toString("utf-8");
56
55
  }
57
- if (options.cssData || options.cssPath) {
56
+ if (out) {
58
57
  return this.callback(null, out || "");
59
58
  }
60
59
  this.callback({ message: `No CSS found`, name: "missing_css" });
61
60
  }
62
- __name(loader, "loader");
63
61
  // Annotate the CommonJS export names for ESM import in node:
64
62
  0 && (module.exports = {
65
63
  extractedInfoByFile,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/css.ts"],
4
- "sourcesContent": ["import { ExtractedResponse, TamaguiOptions } from '@tamagui/static'\nimport { LoaderContext } from 'webpack'\n\nexport const extractedInfoByFile = new Map<string, ExtractedResponse>()\nexport const stylePathToFilePath = new Map<string, string>()\n\nexport default function loader(this: LoaderContext<any>, source: string) {\n this.async()\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n let out = ''\n if (options.cssPath) {\n // get in memory info\n const pathKey = stylePathToFilePath.get(sourcePath) ?? sourcePath\n const info = extractedInfoByFile.get(pathKey)\n // clear memory\n stylePathToFilePath.delete(sourcePath)\n extractedInfoByFile.delete(pathKey)\n const out = info?.styles\n return this.callback(null, out || '')\n } else if (options.cssData) {\n // get output CSS\n out = Buffer.from(options.cssData, 'base64').toString('utf-8')\n }\n if (options.cssData || options.cssPath) {\n // use original JS sourcemap\n return this.callback(null, out || '')\n }\n this.callback({ message: `No CSS found`, name: 'missing_css' })\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,sBAAsB,oBAAI,IAA+B;AAC/D,MAAM,sBAAsB,oBAAI,IAAoB;AAE5C,gBAA0C,QAAgB;AACvE,OAAK,MAAM;AACX,QAAM,UAA0B,mBAAK,KAAK,WAAW;AACrD,QAAM,aAAa,GAAG,KAAK;AAC3B,MAAI,MAAM;AACV,MAAI,QAAQ,SAAS;AAEnB,UAAM,UAAU,oBAAoB,IAAI,UAAU,KAAK;AACvD,UAAM,OAAO,oBAAoB,IAAI,OAAO;AAE5C,wBAAoB,OAAO,UAAU;AACrC,wBAAoB,OAAO,OAAO;AAClC,UAAM,OAAM,6BAAM;AAClB,WAAO,KAAK,SAAS,MAAM,QAAO,EAAE;AAAA,EACtC,WAAW,QAAQ,SAAS;AAE1B,UAAM,OAAO,KAAK,QAAQ,SAAS,QAAQ,EAAE,SAAS,OAAO;AAAA,EAC/D;AACA,MAAI,QAAQ,WAAW,QAAQ,SAAS;AAEtC,WAAO,KAAK,SAAS,MAAM,OAAO,EAAE;AAAA,EACtC;AACA,OAAK,SAAS,EAAE,SAAS,gBAAgB,MAAM,cAAc,CAAC;AAChE;AAvBwB;",
4
+ "sourcesContent": ["import { ExtractedResponse, TamaguiOptions } from '@tamagui/static'\nimport { LoaderContext } from 'webpack'\n\nexport const extractedInfoByFile = new Map<string, ExtractedResponse>()\nexport const stylePathToFilePath = new Map<string, string>()\n\nexport default function loader(this: LoaderContext<any>) {\n this.async()\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n let out = ''\n if (options.cssPath) {\n // get in memory info\n const pathKey = stylePathToFilePath.get(sourcePath) ?? sourcePath\n const info = extractedInfoByFile.get(pathKey)\n // clear memory\n stylePathToFilePath.delete(sourcePath)\n extractedInfoByFile.delete(pathKey)\n const out = info?.styles\n return this.callback(null, out || '')\n } else if (options.cssData) {\n // get output CSS\n out = Buffer.from(options.cssData, 'base64').toString('utf-8')\n }\n if (out) {\n // use original JS sourcemap\n return this.callback(null, out || '')\n }\n this.callback({ message: `No CSS found`, name: 'missing_css' })\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,sBAAsB,oBAAI,IAA+B;AAC/D,MAAM,sBAAsB,oBAAI,IAAoB;AAE5C,kBAA0C;AACvD,OAAK,MAAM;AACX,QAAM,UAA0B,mBAAK,KAAK,WAAW;AACrD,QAAM,aAAa,GAAG,KAAK;AAC3B,MAAI,MAAM;AACV,MAAI,QAAQ,SAAS;AAEnB,UAAM,UAAU,oBAAoB,IAAI,UAAU,KAAK;AACvD,UAAM,OAAO,oBAAoB,IAAI,OAAO;AAE5C,wBAAoB,OAAO,UAAU;AACrC,wBAAoB,OAAO,OAAO;AAClC,UAAM,OAAM,6BAAM;AAClB,WAAO,KAAK,SAAS,MAAM,QAAO,EAAE;AAAA,EACtC,WAAW,QAAQ,SAAS;AAE1B,UAAM,OAAO,KAAK,QAAQ,SAAS,QAAQ,EAAE,SAAS,OAAO;AAAA,EAC/D;AACA,MAAI,KAAK;AAEP,WAAO,KAAK,SAAS,MAAM,OAAO,EAAE;AAAA,EACtC;AACA,OAAK,SAAS,EAAE,SAAS,gBAAgB,MAAM,cAAc,CAAC;AAChE;",
6
6
  "names": []
7
7
  }
package/dist/cjs/index.js CHANGED
@@ -2,7 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
5
  var __export = (target, all) => {
7
6
  for (var name in all)
8
7
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -25,12 +24,12 @@ module.exports = __toCommonJS(src_exports);
25
24
  process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || "web";
26
25
  process.env.TAMAGUI_COMPILE_PROCESS = "1";
27
26
  var src_default = require("./loader").loader;
28
- const shouldExclude = /* @__PURE__ */ __name((path, projectRoot, tamaguiOptions) => {
27
+ const shouldExclude = (path, projectRoot) => {
29
28
  if (path.includes("react-native-reanimated") || path.includes("react-native-gesture-handler") || path.includes("@gorhom/portal") || path.includes(projectRoot) || path.includes("/dist/jsx/")) {
30
29
  return false;
31
30
  }
32
31
  return true;
33
- }, "shouldExclude");
32
+ };
34
33
  // Annotate the CommonJS export names for ESM import in node:
35
34
  0 && (module.exports = {
36
35
  shouldExclude
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || 'web'\nprocess.env.TAMAGUI_COMPILE_PROCESS = '1'\n\nexport default require('./loader').loader\n\n// helper for webpack exclude specific to tamagui\n\nexport const shouldExclude = (path: string, projectRoot: string, tamaguiOptions: any) => {\n if (\n path.includes('react-native-reanimated') ||\n path.includes('react-native-gesture-handler') ||\n path.includes('@gorhom/portal') ||\n path.includes(projectRoot) ||\n path.includes('/dist/jsx/')\n ) {\n return false\n }\n return true\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB;AAC3D,QAAQ,IAAI,0BAA0B;AAEtC,IAAO,cAAQ,QAAQ,UAAU,EAAE;AAI5B,MAAM,gBAAgB,wBAAC,MAAc,aAAqB,mBAAwB;AACvF,MACE,KAAK,SAAS,yBAAyB,KACvC,KAAK,SAAS,8BAA8B,KAC5C,KAAK,SAAS,gBAAgB,KAC9B,KAAK,SAAS,WAAW,KACzB,KAAK,SAAS,YAAY,GAC1B;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT,GAX6B;",
4
+ "sourcesContent": ["process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || 'web'\nprocess.env.TAMAGUI_COMPILE_PROCESS = '1'\n\nexport default require('./loader').loader\n\n// helper for webpack exclude specific to tamagui\n\nexport const shouldExclude = (path: string, projectRoot: string) => {\n if (\n path.includes('react-native-reanimated') ||\n path.includes('react-native-gesture-handler') ||\n path.includes('@gorhom/portal') ||\n path.includes(projectRoot) ||\n path.includes('/dist/jsx/')\n ) {\n return false\n }\n return true\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB;AAC3D,QAAQ,IAAI,0BAA0B;AAEtC,IAAO,cAAQ,QAAQ,UAAU,EAAE;AAI5B,MAAM,gBAAgB,CAAC,MAAc,gBAAwB;AAClE,MACE,KAAK,SAAS,yBAAyB,KACvC,KAAK,SAAS,8BAA8B,KAC5C,KAAK,SAAS,gBAAgB,KAC9B,KAAK,SAAS,WAAW,KACzB,KAAK,SAAS,YAAY,GAC1B;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -18,7 +18,6 @@ var __spreadValues = (a, b) => {
18
18
  }
19
19
  return a;
20
20
  };
21
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
22
21
  var __export = (target, all) => {
23
22
  for (var name in all)
24
23
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -40,15 +39,16 @@ __export(loader_exports, {
40
39
  module.exports = __toCommonJS(loader_exports);
41
40
  var import_static = require("@tamagui/static");
42
41
  var import_css = require("./css");
42
+ const CSS_LOADER_PATH = require.resolve("./css");
43
43
  Error.stackTraceLimit = Infinity;
44
44
  const extractor = (0, import_static.createExtractor)();
45
45
  let index = 0;
46
- let hasLogged = false;
47
46
  let hasPatched = false;
48
47
  process.env.TAMAGUI_TARGET = "web";
49
- function loader(source) {
50
- this.cacheable();
48
+ const loader = function loader2(sourceIn) {
49
+ this.cacheable(true);
51
50
  this.async();
51
+ const source = sourceIn.toString();
52
52
  if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {
53
53
  (0, import_static.patchReactNativeWeb)();
54
54
  hasPatched = true;
@@ -67,19 +67,23 @@ function loader(source) {
67
67
  }
68
68
  const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`;
69
69
  const extracted = (0, import_static.extractToClassNames)({
70
- loader: this,
71
70
  extractor,
72
- cssLoaderPath: require.resolve("./css"),
73
71
  source,
74
- threaded,
75
72
  sourcePath,
76
- cssPath,
77
73
  options,
78
74
  shouldPrintDebug
79
75
  });
80
76
  if (!extracted) {
81
77
  return this.callback(null, source);
82
78
  }
79
+ if (extracted.styles) {
80
+ const cssQuery = threaded ? `cssData=${Buffer.from(extracted.styles).toString("base64")}` : `cssPath=${cssPath}`;
81
+ const remReq = this.remainingRequest;
82
+ const importPath = `${cssPath}!=!${CSS_LOADER_PATH}?${cssQuery}!${remReq}`;
83
+ extracted.js = `${extracted.js}
84
+
85
+ require(${JSON.stringify(importPath)})`;
86
+ }
83
87
  import_css.extractedInfoByFile.set(sourcePath, extracted);
84
88
  if (!threaded) {
85
89
  if (extracted.stylesPath) {
@@ -91,8 +95,7 @@ function loader(source) {
91
95
  console.error("ERROR", err);
92
96
  return this.callback(null, source);
93
97
  }
94
- }
95
- __name(loader, "loader");
98
+ };
96
99
  // Annotate the CommonJS export names for ESM import in node:
97
100
  0 && (module.exports = {
98
101
  loader
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/loader.ts"],
4
- "sourcesContent": ["import {\n ExtractedResponse,\n TamaguiOptions,\n createExtractor,\n extractToClassNames,\n patchReactNativeWeb,\n} from '@tamagui/static'\nimport { LoaderContext } from 'webpack'\n\nimport { extractedInfoByFile, stylePathToFilePath } from './css'\n\nError.stackTraceLimit = Infinity\nconst extractor = createExtractor()\n\nlet index = 0\nlet hasLogged = false\nlet hasPatched = false\n\nprocess.env.TAMAGUI_TARGET = 'web'\n\nexport function loader(this: LoaderContext<any>, source: string) {\n this.cacheable()\n this.async()\n\n if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {\n patchReactNativeWeb()\n hasPatched = true\n }\n\n try {\n const threaded = this.emitFile === undefined\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n const startsWithComment = source[0] === '/' && source[1] === '/'\n\n let shouldPrintDebug: boolean | 'verbose' =\n (!!process.env.DEBUG &&\n (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true)) ||\n // supports esbuild style //! comments\n (startsWithComment && (source.startsWith('// debug') || source.startsWith('//! debug')))\n\n if (shouldPrintDebug && source.startsWith('// debug-verbose')) {\n shouldPrintDebug = 'verbose'\n }\n\n // check if should ignore\n if (\n startsWithComment &&\n (source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))\n ) {\n return this.callback(null, source)\n }\n\n const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`\n\n const extracted = extractToClassNames({\n loader: this,\n extractor,\n cssLoaderPath: require.resolve('./css'),\n source,\n threaded,\n sourcePath,\n cssPath,\n options,\n shouldPrintDebug,\n })\n\n if (!extracted) {\n return this.callback(null, source)\n }\n\n extractedInfoByFile.set(sourcePath, extracted)\n\n if (!threaded) {\n if (extracted.stylesPath) {\n stylePathToFilePath.set(extracted.stylesPath, sourcePath)\n }\n }\n\n this.callback(null, extracted.js, extracted.map)\n } catch (err) {\n console.error('ERROR', err)\n return this.callback(null, source)\n }\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAMO;AAGP,iBAAyD;AAEzD,MAAM,kBAAkB;AACxB,MAAM,YAAY,mCAAgB;AAElC,IAAI,QAAQ;AACZ,IAAI,YAAY;AAChB,IAAI,aAAa;AAEjB,QAAQ,IAAI,iBAAiB;AAEtB,gBAA0C,QAAgB;AAC/D,OAAK,UAAU;AACf,OAAK,MAAM;AAEX,MAAI,CAAC,QAAQ,IAAI,6BAA6B,CAAC,YAAY;AACzD,2CAAoB;AACpB,iBAAa;AAAA,EACf;AAEA,MAAI;AACF,UAAM,WAAW,KAAK,aAAa;AACnC,UAAM,UAA0B,mBAAK,KAAK,WAAW;AACrD,UAAM,aAAa,GAAG,KAAK;AAC3B,UAAM,oBAAoB,OAAO,OAAO,OAAO,OAAO,OAAO;AAE7D,QAAI,mBACD,CAAC,CAAC,QAAQ,IAAI,SACZ,SAAQ,IAAI,aAAa,WAAW,SAAS,QAAQ,IAAI,UAAU,IAAI,SAEzE,qBAAsB,QAAO,WAAW,UAAU,KAAK,OAAO,WAAW,WAAW;AAEvF,QAAI,oBAAoB,OAAO,WAAW,kBAAkB,GAAG;AAC7D,yBAAmB;AAAA,IACrB;AAGA,QACE,qBACC,QAAO,WAAW,mBAAmB,KAAK,OAAO,WAAW,oBAAoB,IACjF;AACA,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAEA,UAAM,UAAU,WAAW,GAAG,0BAA0B,GAAG,cAAc;AAEzE,UAAM,YAAY,uCAAoB;AAAA,MACpC,QAAQ;AAAA,MACR;AAAA,MACA,eAA+B;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,WAAW;AACd,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAEA,mCAAoB,IAAI,YAAY,SAAS;AAE7C,QAAI,CAAC,UAAU;AACb,UAAI,UAAU,YAAY;AACxB,uCAAoB,IAAI,UAAU,YAAY,UAAU;AAAA,MAC1D;AAAA,IACF;AAEA,SAAK,SAAS,MAAM,UAAU,IAAI,UAAU,GAAG;AAAA,EACjD,SAAS,KAAP;AACA,YAAQ,MAAM,SAAS,GAAG;AAC1B,WAAO,KAAK,SAAS,MAAM,MAAM;AAAA,EACnC;AACF;AAhEgB;",
4
+ "sourcesContent": ["import {\n TamaguiOptions,\n createExtractor,\n extractToClassNames,\n patchReactNativeWeb,\n} from '@tamagui/static'\nimport type { LoaderContext, RawLoaderDefinitionFunction } from 'webpack'\n\nimport { extractedInfoByFile, stylePathToFilePath } from './css'\n\n// pass loader as path\nconst CSS_LOADER_PATH = require.resolve('./css')\n\nError.stackTraceLimit = Infinity\nconst extractor = createExtractor()\n\nlet index = 0\nlet hasPatched = false\n\nprocess.env.TAMAGUI_TARGET = 'web'\n\nexport const loader: RawLoaderDefinitionFunction<TamaguiOptions> = function loader(this, sourceIn) {\n this.cacheable(true)\n this.async()\n const source = sourceIn.toString()\n\n if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {\n patchReactNativeWeb()\n hasPatched = true\n }\n\n try {\n const threaded = this.emitFile === undefined\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n const startsWithComment = source[0] === '/' && source[1] === '/'\n\n let shouldPrintDebug: boolean | 'verbose' =\n (!!process.env.DEBUG &&\n (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true)) ||\n // supports esbuild style //! comments\n (startsWithComment && (source.startsWith('// debug') || source.startsWith('//! debug')))\n\n if (shouldPrintDebug && source.startsWith('// debug-verbose')) {\n shouldPrintDebug = 'verbose'\n }\n\n // check if should ignore\n if (\n startsWithComment &&\n (source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))\n ) {\n return this.callback(null, source)\n }\n\n const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`\n\n const extracted = extractToClassNames({\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n })\n\n if (!extracted) {\n return this.callback(null, source)\n }\n\n // add import to css\n if (extracted.styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(extracted.styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = this.remainingRequest\n const importPath = `${cssPath}!=!${CSS_LOADER_PATH}?${cssQuery}!${remReq}`\n extracted.js = `${extracted.js}\\n\\nrequire(${JSON.stringify(importPath)})`\n }\n\n extractedInfoByFile.set(sourcePath, extracted)\n\n if (!threaded) {\n if (extracted.stylesPath) {\n stylePathToFilePath.set(extracted.stylesPath, sourcePath)\n }\n }\n\n this.callback(null, extracted.js, extracted.map)\n } catch (err) {\n console.error('ERROR', err)\n return this.callback(null, source)\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAKO;AAGP,iBAAyD;AAGzD,MAAM,kBAAkC;AAExC,MAAM,kBAAkB;AACxB,MAAM,YAAY,mCAAgB;AAElC,IAAI,QAAQ;AACZ,IAAI,aAAa;AAEjB,QAAQ,IAAI,iBAAiB;AAEtB,MAAM,SAAsD,iBAAsB,UAAU;AACjG,OAAK,UAAU,IAAI;AACnB,OAAK,MAAM;AACX,QAAM,SAAS,SAAS,SAAS;AAEjC,MAAI,CAAC,QAAQ,IAAI,6BAA6B,CAAC,YAAY;AACzD,2CAAoB;AACpB,iBAAa;AAAA,EACf;AAEA,MAAI;AACF,UAAM,WAAW,KAAK,aAAa;AACnC,UAAM,UAA0B,mBAAK,KAAK,WAAW;AACrD,UAAM,aAAa,GAAG,KAAK;AAC3B,UAAM,oBAAoB,OAAO,OAAO,OAAO,OAAO,OAAO;AAE7D,QAAI,mBACD,CAAC,CAAC,QAAQ,IAAI,SACZ,SAAQ,IAAI,aAAa,WAAW,SAAS,QAAQ,IAAI,UAAU,IAAI,SAEzE,qBAAsB,QAAO,WAAW,UAAU,KAAK,OAAO,WAAW,WAAW;AAEvF,QAAI,oBAAoB,OAAO,WAAW,kBAAkB,GAAG;AAC7D,yBAAmB;AAAA,IACrB;AAGA,QACE,qBACC,QAAO,WAAW,mBAAmB,KAAK,OAAO,WAAW,oBAAoB,IACjF;AACA,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAEA,UAAM,UAAU,WAAW,GAAG,0BAA0B,GAAG,cAAc;AAEzE,UAAM,YAAY,uCAAoB;AAAA,MACpC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,WAAW;AACd,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAGA,QAAI,UAAU,QAAQ;AACpB,YAAM,WAAW,WACb,WAAW,OAAO,KAAK,UAAU,MAAM,EAAE,SAAS,QAAQ,MAC1D,WAAW;AACf,YAAM,SAAS,KAAK;AACpB,YAAM,aAAa,GAAG,aAAa,mBAAmB,YAAY;AAClE,gBAAU,KAAK,GAAG,UAAU;AAAA;AAAA,UAAiB,KAAK,UAAU,UAAU;AAAA,IACxE;AAEA,mCAAoB,IAAI,YAAY,SAAS;AAE7C,QAAI,CAAC,UAAU;AACb,UAAI,UAAU,YAAY;AACxB,uCAAoB,IAAI,UAAU,YAAY,UAAU;AAAA,MAC1D;AAAA,IACF;AAEA,SAAK,SAAS,MAAM,UAAU,IAAI,UAAU,GAAG;AAAA,EACjD,SAAS,KAAP;AACA,YAAQ,MAAM,SAAS,GAAG;AAC1B,WAAO,KAAK,SAAS,MAAM,MAAM;AAAA,EACnC;AACF;",
6
6
  "names": []
7
7
  }
package/dist/esm/css.js CHANGED
@@ -1,15 +1,28 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
3
17
  const extractedInfoByFile = /* @__PURE__ */ new Map();
4
18
  const stylePathToFilePath = /* @__PURE__ */ new Map();
5
- function loader(source) {
6
- var _a;
19
+ function loader() {
7
20
  this.async();
8
- const options = { ...this.getOptions() };
21
+ const options = __spreadValues({}, this.getOptions());
9
22
  const sourcePath = `${this.resourcePath}`;
10
23
  let out = "";
11
24
  if (options.cssPath) {
12
- const pathKey = (_a = stylePathToFilePath.get(sourcePath)) != null ? _a : sourcePath;
25
+ const pathKey = stylePathToFilePath.get(sourcePath) ?? sourcePath;
13
26
  const info = extractedInfoByFile.get(pathKey);
14
27
  stylePathToFilePath.delete(sourcePath);
15
28
  extractedInfoByFile.delete(pathKey);
@@ -18,12 +31,11 @@ function loader(source) {
18
31
  } else if (options.cssData) {
19
32
  out = Buffer.from(options.cssData, "base64").toString("utf-8");
20
33
  }
21
- if (options.cssData || options.cssPath) {
34
+ if (out) {
22
35
  return this.callback(null, out || "");
23
36
  }
24
37
  this.callback({ message: `No CSS found`, name: "missing_css" });
25
38
  }
26
- __name(loader, "loader");
27
39
  export {
28
40
  loader as default,
29
41
  extractedInfoByFile,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/css.ts"],
4
- "sourcesContent": ["import { ExtractedResponse, TamaguiOptions } from '@tamagui/static'\nimport { LoaderContext } from 'webpack'\n\nexport const extractedInfoByFile = new Map<string, ExtractedResponse>()\nexport const stylePathToFilePath = new Map<string, string>()\n\nexport default function loader(this: LoaderContext<any>, source: string) {\n this.async()\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n let out = ''\n if (options.cssPath) {\n // get in memory info\n const pathKey = stylePathToFilePath.get(sourcePath) ?? sourcePath\n const info = extractedInfoByFile.get(pathKey)\n // clear memory\n stylePathToFilePath.delete(sourcePath)\n extractedInfoByFile.delete(pathKey)\n const out = info?.styles\n return this.callback(null, out || '')\n } else if (options.cssData) {\n // get output CSS\n out = Buffer.from(options.cssData, 'base64').toString('utf-8')\n }\n if (options.cssData || options.cssPath) {\n // use original JS sourcemap\n return this.callback(null, out || '')\n }\n this.callback({ message: `No CSS found`, name: 'missing_css' })\n}\n"],
5
- "mappings": ";;AAGO,MAAM,sBAAsB,oBAAI,IAA+B;AAC/D,MAAM,sBAAsB,oBAAI,IAAoB;AAE5C,gBAA0C,QAAgB;AANzE;AAOE,OAAK,MAAM;AACX,QAAM,UAA0B,KAAK,KAAK,WAAW,EAAE;AACvD,QAAM,aAAa,GAAG,KAAK;AAC3B,MAAI,MAAM;AACV,MAAI,QAAQ,SAAS;AAEnB,UAAM,UAAU,0BAAoB,IAAI,UAAU,MAAlC,YAAuC;AACvD,UAAM,OAAO,oBAAoB,IAAI,OAAO;AAE5C,wBAAoB,OAAO,UAAU;AACrC,wBAAoB,OAAO,OAAO;AAClC,UAAM,OAAM,6BAAM;AAClB,WAAO,KAAK,SAAS,MAAM,QAAO,EAAE;AAAA,EACtC,WAAW,QAAQ,SAAS;AAE1B,UAAM,OAAO,KAAK,QAAQ,SAAS,QAAQ,EAAE,SAAS,OAAO;AAAA,EAC/D;AACA,MAAI,QAAQ,WAAW,QAAQ,SAAS;AAEtC,WAAO,KAAK,SAAS,MAAM,OAAO,EAAE;AAAA,EACtC;AACA,OAAK,SAAS,EAAE,SAAS,gBAAgB,MAAM,cAAc,CAAC;AAChE;AAvBwB;",
4
+ "sourcesContent": ["import { ExtractedResponse, TamaguiOptions } from '@tamagui/static'\nimport { LoaderContext } from 'webpack'\n\nexport const extractedInfoByFile = new Map<string, ExtractedResponse>()\nexport const stylePathToFilePath = new Map<string, string>()\n\nexport default function loader(this: LoaderContext<any>) {\n this.async()\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n let out = ''\n if (options.cssPath) {\n // get in memory info\n const pathKey = stylePathToFilePath.get(sourcePath) ?? sourcePath\n const info = extractedInfoByFile.get(pathKey)\n // clear memory\n stylePathToFilePath.delete(sourcePath)\n extractedInfoByFile.delete(pathKey)\n const out = info?.styles\n return this.callback(null, out || '')\n } else if (options.cssData) {\n // get output CSS\n out = Buffer.from(options.cssData, 'base64').toString('utf-8')\n }\n if (out) {\n // use original JS sourcemap\n return this.callback(null, out || '')\n }\n this.callback({ message: `No CSS found`, name: 'missing_css' })\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;AAGO,MAAM,sBAAsB,oBAAI,IAA+B;AAC/D,MAAM,sBAAsB,oBAAI,IAAoB;AAE5C,kBAA0C;AACvD,OAAK,MAAM;AACX,QAAM,UAA0B,mBAAK,KAAK,WAAW;AACrD,QAAM,aAAa,GAAG,KAAK;AAC3B,MAAI,MAAM;AACV,MAAI,QAAQ,SAAS;AAEnB,UAAM,UAAU,oBAAoB,IAAI,UAAU,KAAK;AACvD,UAAM,OAAO,oBAAoB,IAAI,OAAO;AAE5C,wBAAoB,OAAO,UAAU;AACrC,wBAAoB,OAAO,OAAO;AAClC,UAAM,OAAM,6BAAM;AAClB,WAAO,KAAK,SAAS,MAAM,QAAO,EAAE;AAAA,EACtC,WAAW,QAAQ,SAAS;AAE1B,UAAM,OAAO,KAAK,QAAQ,SAAS,QAAQ,EAAE,SAAS,OAAO;AAAA,EAC/D;AACA,MAAI,KAAK;AAEP,WAAO,KAAK,SAAS,MAAM,OAAO,EAAE;AAAA,EACtC;AACA,OAAK,SAAS,EAAE,SAAS,gBAAgB,MAAM,cAAc,CAAC;AAChE;",
6
6
  "names": []
7
7
  }
package/dist/esm/index.js CHANGED
@@ -1,14 +1,12 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
1
  process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || "web";
4
2
  process.env.TAMAGUI_COMPILE_PROCESS = "1";
5
3
  var src_default = require("./loader").loader;
6
- const shouldExclude = /* @__PURE__ */ __name((path, projectRoot, tamaguiOptions) => {
4
+ const shouldExclude = (path, projectRoot) => {
7
5
  if (path.includes("react-native-reanimated") || path.includes("react-native-gesture-handler") || path.includes("@gorhom/portal") || path.includes(projectRoot) || path.includes("/dist/jsx/")) {
8
6
  return false;
9
7
  }
10
8
  return true;
11
- }, "shouldExclude");
9
+ };
12
10
  export {
13
11
  src_default as default,
14
12
  shouldExclude
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || 'web'\nprocess.env.TAMAGUI_COMPILE_PROCESS = '1'\n\nexport default require('./loader').loader\n\n// helper for webpack exclude specific to tamagui\n\nexport const shouldExclude = (path: string, projectRoot: string, tamaguiOptions: any) => {\n if (\n path.includes('react-native-reanimated') ||\n path.includes('react-native-gesture-handler') ||\n path.includes('@gorhom/portal') ||\n path.includes(projectRoot) ||\n path.includes('/dist/jsx/')\n ) {\n return false\n }\n return true\n}\n"],
5
- "mappings": ";;AAAA,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB;AAC3D,QAAQ,IAAI,0BAA0B;AAEtC,IAAO,cAAQ,QAAQ,UAAU,EAAE;AAI5B,MAAM,gBAAgB,wBAAC,MAAc,aAAqB,mBAAwB;AACvF,MACE,KAAK,SAAS,yBAAyB,KACvC,KAAK,SAAS,8BAA8B,KAC5C,KAAK,SAAS,gBAAgB,KAC9B,KAAK,SAAS,WAAW,KACzB,KAAK,SAAS,YAAY,GAC1B;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT,GAX6B;",
4
+ "sourcesContent": ["process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || 'web'\nprocess.env.TAMAGUI_COMPILE_PROCESS = '1'\n\nexport default require('./loader').loader\n\n// helper for webpack exclude specific to tamagui\n\nexport const shouldExclude = (path: string, projectRoot: string) => {\n if (\n path.includes('react-native-reanimated') ||\n path.includes('react-native-gesture-handler') ||\n path.includes('@gorhom/portal') ||\n path.includes(projectRoot) ||\n path.includes('/dist/jsx/')\n ) {\n return false\n }\n return true\n}\n"],
5
+ "mappings": "AAAA,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB;AAC3D,QAAQ,IAAI,0BAA0B;AAEtC,IAAO,cAAQ,QAAQ,UAAU,EAAE;AAI5B,MAAM,gBAAgB,CAAC,MAAc,gBAAwB;AAClE,MACE,KAAK,SAAS,yBAAyB,KACvC,KAAK,SAAS,8BAA8B,KAC5C,KAAK,SAAS,gBAAgB,KAC9B,KAAK,SAAS,WAAW,KACzB,KAAK,SAAS,YAAY,GAC1B;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;",
6
6
  "names": []
7
7
  }
@@ -1,27 +1,42 @@
1
1
  var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
3
17
  import {
4
18
  createExtractor,
5
19
  extractToClassNames,
6
20
  patchReactNativeWeb
7
21
  } from "@tamagui/static";
8
22
  import { extractedInfoByFile, stylePathToFilePath } from "./css";
23
+ const CSS_LOADER_PATH = require.resolve("./css");
9
24
  Error.stackTraceLimit = Infinity;
10
25
  const extractor = createExtractor();
11
26
  let index = 0;
12
- let hasLogged = false;
13
27
  let hasPatched = false;
14
28
  process.env.TAMAGUI_TARGET = "web";
15
- function loader(source) {
16
- this.cacheable();
29
+ const loader = function loader2(sourceIn) {
30
+ this.cacheable(true);
17
31
  this.async();
32
+ const source = sourceIn.toString();
18
33
  if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {
19
34
  patchReactNativeWeb();
20
35
  hasPatched = true;
21
36
  }
22
37
  try {
23
38
  const threaded = this.emitFile === void 0;
24
- const options = { ...this.getOptions() };
39
+ const options = __spreadValues({}, this.getOptions());
25
40
  const sourcePath = `${this.resourcePath}`;
26
41
  const startsWithComment = source[0] === "/" && source[1] === "/";
27
42
  let shouldPrintDebug = !!process.env.DEBUG && (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true) || startsWithComment && (source.startsWith("// debug") || source.startsWith("//! debug"));
@@ -33,19 +48,23 @@ function loader(source) {
33
48
  }
34
49
  const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`;
35
50
  const extracted = extractToClassNames({
36
- loader: this,
37
51
  extractor,
38
- cssLoaderPath: require.resolve("./css"),
39
52
  source,
40
- threaded,
41
53
  sourcePath,
42
- cssPath,
43
54
  options,
44
55
  shouldPrintDebug
45
56
  });
46
57
  if (!extracted) {
47
58
  return this.callback(null, source);
48
59
  }
60
+ if (extracted.styles) {
61
+ const cssQuery = threaded ? `cssData=${Buffer.from(extracted.styles).toString("base64")}` : `cssPath=${cssPath}`;
62
+ const remReq = this.remainingRequest;
63
+ const importPath = `${cssPath}!=!${CSS_LOADER_PATH}?${cssQuery}!${remReq}`;
64
+ extracted.js = `${extracted.js}
65
+
66
+ require(${JSON.stringify(importPath)})`;
67
+ }
49
68
  extractedInfoByFile.set(sourcePath, extracted);
50
69
  if (!threaded) {
51
70
  if (extracted.stylesPath) {
@@ -57,8 +76,7 @@ function loader(source) {
57
76
  console.error("ERROR", err);
58
77
  return this.callback(null, source);
59
78
  }
60
- }
61
- __name(loader, "loader");
79
+ };
62
80
  export {
63
81
  loader
64
82
  };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/loader.ts"],
4
- "sourcesContent": ["import {\n ExtractedResponse,\n TamaguiOptions,\n createExtractor,\n extractToClassNames,\n patchReactNativeWeb,\n} from '@tamagui/static'\nimport { LoaderContext } from 'webpack'\n\nimport { extractedInfoByFile, stylePathToFilePath } from './css'\n\nError.stackTraceLimit = Infinity\nconst extractor = createExtractor()\n\nlet index = 0\nlet hasLogged = false\nlet hasPatched = false\n\nprocess.env.TAMAGUI_TARGET = 'web'\n\nexport function loader(this: LoaderContext<any>, source: string) {\n this.cacheable()\n this.async()\n\n if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {\n patchReactNativeWeb()\n hasPatched = true\n }\n\n try {\n const threaded = this.emitFile === undefined\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n const startsWithComment = source[0] === '/' && source[1] === '/'\n\n let shouldPrintDebug: boolean | 'verbose' =\n (!!process.env.DEBUG &&\n (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true)) ||\n // supports esbuild style //! comments\n (startsWithComment && (source.startsWith('// debug') || source.startsWith('//! debug')))\n\n if (shouldPrintDebug && source.startsWith('// debug-verbose')) {\n shouldPrintDebug = 'verbose'\n }\n\n // check if should ignore\n if (\n startsWithComment &&\n (source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))\n ) {\n return this.callback(null, source)\n }\n\n const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`\n\n const extracted = extractToClassNames({\n loader: this,\n extractor,\n cssLoaderPath: require.resolve('./css'),\n source,\n threaded,\n sourcePath,\n cssPath,\n options,\n shouldPrintDebug,\n })\n\n if (!extracted) {\n return this.callback(null, source)\n }\n\n extractedInfoByFile.set(sourcePath, extracted)\n\n if (!threaded) {\n if (extracted.stylesPath) {\n stylePathToFilePath.set(extracted.stylesPath, sourcePath)\n }\n }\n\n this.callback(null, extracted.js, extracted.map)\n } catch (err) {\n console.error('ERROR', err)\n return this.callback(null, source)\n }\n}\n"],
5
- "mappings": ";;AAAA;AAAA;AAAA;AAAA;AAAA;AASA;AAEA,MAAM,kBAAkB;AACxB,MAAM,YAAY,gBAAgB;AAElC,IAAI,QAAQ;AACZ,IAAI,YAAY;AAChB,IAAI,aAAa;AAEjB,QAAQ,IAAI,iBAAiB;AAEtB,gBAA0C,QAAgB;AAC/D,OAAK,UAAU;AACf,OAAK,MAAM;AAEX,MAAI,CAAC,QAAQ,IAAI,6BAA6B,CAAC,YAAY;AACzD,wBAAoB;AACpB,iBAAa;AAAA,EACf;AAEA,MAAI;AACF,UAAM,WAAW,KAAK,aAAa;AACnC,UAAM,UAA0B,KAAK,KAAK,WAAW,EAAE;AACvD,UAAM,aAAa,GAAG,KAAK;AAC3B,UAAM,oBAAoB,OAAO,OAAO,OAAO,OAAO,OAAO;AAE7D,QAAI,mBACD,CAAC,CAAC,QAAQ,IAAI,SACZ,SAAQ,IAAI,aAAa,WAAW,SAAS,QAAQ,IAAI,UAAU,IAAI,SAEzE,qBAAsB,QAAO,WAAW,UAAU,KAAK,OAAO,WAAW,WAAW;AAEvF,QAAI,oBAAoB,OAAO,WAAW,kBAAkB,GAAG;AAC7D,yBAAmB;AAAA,IACrB;AAGA,QACE,qBACC,QAAO,WAAW,mBAAmB,KAAK,OAAO,WAAW,oBAAoB,IACjF;AACA,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAEA,UAAM,UAAU,WAAW,GAAG,0BAA0B,GAAG,cAAc;AAEzE,UAAM,YAAY,oBAAoB;AAAA,MACpC,QAAQ;AAAA,MACR;AAAA,MACA,eAA+B;AAAA,MAC/B;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,WAAW;AACd,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAEA,wBAAoB,IAAI,YAAY,SAAS;AAE7C,QAAI,CAAC,UAAU;AACb,UAAI,UAAU,YAAY;AACxB,4BAAoB,IAAI,UAAU,YAAY,UAAU;AAAA,MAC1D;AAAA,IACF;AAEA,SAAK,SAAS,MAAM,UAAU,IAAI,UAAU,GAAG;AAAA,EACjD,SAAS,KAAP;AACA,YAAQ,MAAM,SAAS,GAAG;AAC1B,WAAO,KAAK,SAAS,MAAM,MAAM;AAAA,EACnC;AACF;AAhEgB;",
4
+ "sourcesContent": ["import {\n TamaguiOptions,\n createExtractor,\n extractToClassNames,\n patchReactNativeWeb,\n} from '@tamagui/static'\nimport type { LoaderContext, RawLoaderDefinitionFunction } from 'webpack'\n\nimport { extractedInfoByFile, stylePathToFilePath } from './css'\n\n// pass loader as path\nconst CSS_LOADER_PATH = require.resolve('./css')\n\nError.stackTraceLimit = Infinity\nconst extractor = createExtractor()\n\nlet index = 0\nlet hasPatched = false\n\nprocess.env.TAMAGUI_TARGET = 'web'\n\nexport const loader: RawLoaderDefinitionFunction<TamaguiOptions> = function loader(this, sourceIn) {\n this.cacheable(true)\n this.async()\n const source = sourceIn.toString()\n\n if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {\n patchReactNativeWeb()\n hasPatched = true\n }\n\n try {\n const threaded = this.emitFile === undefined\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n const startsWithComment = source[0] === '/' && source[1] === '/'\n\n let shouldPrintDebug: boolean | 'verbose' =\n (!!process.env.DEBUG &&\n (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true)) ||\n // supports esbuild style //! comments\n (startsWithComment && (source.startsWith('// debug') || source.startsWith('//! debug')))\n\n if (shouldPrintDebug && source.startsWith('// debug-verbose')) {\n shouldPrintDebug = 'verbose'\n }\n\n // check if should ignore\n if (\n startsWithComment &&\n (source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))\n ) {\n return this.callback(null, source)\n }\n\n const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`\n\n const extracted = extractToClassNames({\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n })\n\n if (!extracted) {\n return this.callback(null, source)\n }\n\n // add import to css\n if (extracted.styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(extracted.styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = this.remainingRequest\n const importPath = `${cssPath}!=!${CSS_LOADER_PATH}?${cssQuery}!${remReq}`\n extracted.js = `${extracted.js}\\n\\nrequire(${JSON.stringify(importPath)})`\n }\n\n extractedInfoByFile.set(sourcePath, extracted)\n\n if (!threaded) {\n if (extracted.stylesPath) {\n stylePathToFilePath.set(extracted.stylesPath, sourcePath)\n }\n }\n\n this.callback(null, extracted.js, extracted.map)\n } catch (err) {\n console.error('ERROR', err)\n return this.callback(null, source)\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;AAGA,MAAM,kBAAkC;AAExC,MAAM,kBAAkB;AACxB,MAAM,YAAY,gBAAgB;AAElC,IAAI,QAAQ;AACZ,IAAI,aAAa;AAEjB,QAAQ,IAAI,iBAAiB;AAEtB,MAAM,SAAsD,iBAAsB,UAAU;AACjG,OAAK,UAAU,IAAI;AACnB,OAAK,MAAM;AACX,QAAM,SAAS,SAAS,SAAS;AAEjC,MAAI,CAAC,QAAQ,IAAI,6BAA6B,CAAC,YAAY;AACzD,wBAAoB;AACpB,iBAAa;AAAA,EACf;AAEA,MAAI;AACF,UAAM,WAAW,KAAK,aAAa;AACnC,UAAM,UAA0B,mBAAK,KAAK,WAAW;AACrD,UAAM,aAAa,GAAG,KAAK;AAC3B,UAAM,oBAAoB,OAAO,OAAO,OAAO,OAAO,OAAO;AAE7D,QAAI,mBACD,CAAC,CAAC,QAAQ,IAAI,SACZ,SAAQ,IAAI,aAAa,WAAW,SAAS,QAAQ,IAAI,UAAU,IAAI,SAEzE,qBAAsB,QAAO,WAAW,UAAU,KAAK,OAAO,WAAW,WAAW;AAEvF,QAAI,oBAAoB,OAAO,WAAW,kBAAkB,GAAG;AAC7D,yBAAmB;AAAA,IACrB;AAGA,QACE,qBACC,QAAO,WAAW,mBAAmB,KAAK,OAAO,WAAW,oBAAoB,IACjF;AACA,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAEA,UAAM,UAAU,WAAW,GAAG,0BAA0B,GAAG,cAAc;AAEzE,UAAM,YAAY,oBAAoB;AAAA,MACpC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,WAAW;AACd,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAGA,QAAI,UAAU,QAAQ;AACpB,YAAM,WAAW,WACb,WAAW,OAAO,KAAK,UAAU,MAAM,EAAE,SAAS,QAAQ,MAC1D,WAAW;AACf,YAAM,SAAS,KAAK;AACpB,YAAM,aAAa,GAAG,aAAa,mBAAmB,YAAY;AAClE,gBAAU,KAAK,GAAG,UAAU;AAAA;AAAA,UAAiB,KAAK,UAAU,UAAU;AAAA,IACxE;AAEA,wBAAoB,IAAI,YAAY,SAAS;AAE7C,QAAI,CAAC,UAAU;AACb,UAAI,UAAU,YAAY;AACxB,4BAAoB,IAAI,UAAU,YAAY,UAAU;AAAA,MAC1D;AAAA,IACF;AAEA,SAAK,SAAS,MAAM,UAAU,IAAI,UAAU,GAAG;AAAA,EACjD,SAAS,KAAP;AACA,YAAQ,MAAM,SAAS,GAAG;AAC1B,WAAO,KAAK,SAAS,MAAM,MAAM;AAAA,EACnC;AACF;",
6
6
  "names": []
7
7
  }
package/dist/jsx/css.js CHANGED
@@ -1,8 +1,6 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
1
  const extractedInfoByFile = /* @__PURE__ */ new Map();
4
2
  const stylePathToFilePath = /* @__PURE__ */ new Map();
5
- function loader(source) {
3
+ function loader() {
6
4
  var _a;
7
5
  this.async();
8
6
  const options = { ...this.getOptions() };
@@ -18,14 +16,14 @@ function loader(source) {
18
16
  } else if (options.cssData) {
19
17
  out = Buffer.from(options.cssData, "base64").toString("utf-8");
20
18
  }
21
- if (options.cssData || options.cssPath) {
19
+ if (out) {
22
20
  return this.callback(null, out || "");
23
21
  }
24
22
  this.callback({ message: `No CSS found`, name: "missing_css" });
25
23
  }
26
- __name(loader, "loader");
27
24
  export {
28
25
  loader as default,
29
26
  extractedInfoByFile,
30
27
  stylePathToFilePath
31
28
  };
29
+ //# sourceMappingURL=css.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/css.ts"],
4
+ "sourcesContent": ["import { ExtractedResponse, TamaguiOptions } from '@tamagui/static'\nimport { LoaderContext } from 'webpack'\n\nexport const extractedInfoByFile = new Map<string, ExtractedResponse>()\nexport const stylePathToFilePath = new Map<string, string>()\n\nexport default function loader(this: LoaderContext<any>) {\n this.async()\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n let out = ''\n if (options.cssPath) {\n // get in memory info\n const pathKey = stylePathToFilePath.get(sourcePath) ?? sourcePath\n const info = extractedInfoByFile.get(pathKey)\n // clear memory\n stylePathToFilePath.delete(sourcePath)\n extractedInfoByFile.delete(pathKey)\n const out = info?.styles\n return this.callback(null, out || '')\n } else if (options.cssData) {\n // get output CSS\n out = Buffer.from(options.cssData, 'base64').toString('utf-8')\n }\n if (out) {\n // use original JS sourcemap\n return this.callback(null, out || '')\n }\n this.callback({ message: `No CSS found`, name: 'missing_css' })\n}\n"],
5
+ "mappings": "AAGO,MAAM,sBAAsB,oBAAI,IAA+B;AAC/D,MAAM,sBAAsB,oBAAI,IAAoB;AAE5C,kBAA0C;AANzD;AAOE,OAAK,MAAM;AACX,QAAM,UAA0B,EAAE,GAAG,KAAK,WAAW,EAAE;AACvD,QAAM,aAAa,GAAG,KAAK;AAC3B,MAAI,MAAM;AACV,MAAI,QAAQ,SAAS;AAEnB,UAAM,UAAU,0BAAoB,IAAI,UAAU,MAAlC,YAAuC;AACvD,UAAM,OAAO,oBAAoB,IAAI,OAAO;AAE5C,wBAAoB,OAAO,UAAU;AACrC,wBAAoB,OAAO,OAAO;AAClC,UAAM,OAAM,6BAAM;AAClB,WAAO,KAAK,SAAS,MAAM,QAAO,EAAE;AAAA,EACtC,WAAW,QAAQ,SAAS;AAE1B,UAAM,OAAO,KAAK,QAAQ,SAAS,QAAQ,EAAE,SAAS,OAAO;AAAA,EAC/D;AACA,MAAI,KAAK;AAEP,WAAO,KAAK,SAAS,MAAM,OAAO,EAAE;AAAA,EACtC;AACA,OAAK,SAAS,EAAE,SAAS,gBAAgB,MAAM,cAAc,CAAC;AAChE;",
6
+ "names": []
7
+ }
package/dist/jsx/index.js CHANGED
@@ -1,15 +1,14 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
1
  process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || "web";
4
2
  process.env.TAMAGUI_COMPILE_PROCESS = "1";
5
3
  var src_default = require("./loader").loader;
6
- const shouldExclude = /* @__PURE__ */ __name((path, projectRoot, tamaguiOptions) => {
4
+ const shouldExclude = (path, projectRoot) => {
7
5
  if (path.includes("react-native-reanimated") || path.includes("react-native-gesture-handler") || path.includes("@gorhom/portal") || path.includes(projectRoot) || path.includes("/dist/jsx/")) {
8
6
  return false;
9
7
  }
10
8
  return true;
11
- }, "shouldExclude");
9
+ };
12
10
  export {
13
11
  src_default as default,
14
12
  shouldExclude
15
13
  };
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts"],
4
+ "sourcesContent": ["process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || 'web'\nprocess.env.TAMAGUI_COMPILE_PROCESS = '1'\n\nexport default require('./loader').loader\n\n// helper for webpack exclude specific to tamagui\n\nexport const shouldExclude = (path: string, projectRoot: string) => {\n if (\n path.includes('react-native-reanimated') ||\n path.includes('react-native-gesture-handler') ||\n path.includes('@gorhom/portal') ||\n path.includes(projectRoot) ||\n path.includes('/dist/jsx/')\n ) {\n return false\n }\n return true\n}\n"],
5
+ "mappings": "AAAA,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB;AAC3D,QAAQ,IAAI,0BAA0B;AAEtC,IAAO,cAAQ,QAAQ,UAAU,EAAE;AAI5B,MAAM,gBAAgB,CAAC,MAAc,gBAAwB;AAClE,MACE,KAAK,SAAS,yBAAyB,KACvC,KAAK,SAAS,8BAA8B,KAC5C,KAAK,SAAS,gBAAgB,KAC9B,KAAK,SAAS,WAAW,KACzB,KAAK,SAAS,YAAY,GAC1B;AACA,WAAO;AAAA,EACT;AACA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -1,20 +1,19 @@
1
- var __defProp = Object.defineProperty;
2
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
1
  import {
4
2
  createExtractor,
5
3
  extractToClassNames,
6
4
  patchReactNativeWeb
7
5
  } from "@tamagui/static";
8
6
  import { extractedInfoByFile, stylePathToFilePath } from "./css";
7
+ const CSS_LOADER_PATH = require.resolve("./css");
9
8
  Error.stackTraceLimit = Infinity;
10
9
  const extractor = createExtractor();
11
10
  let index = 0;
12
- let hasLogged = false;
13
11
  let hasPatched = false;
14
12
  process.env.TAMAGUI_TARGET = "web";
15
- function loader(source) {
16
- this.cacheable();
13
+ const loader = function loader2(sourceIn) {
14
+ this.cacheable(true);
17
15
  this.async();
16
+ const source = sourceIn.toString();
18
17
  if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {
19
18
  patchReactNativeWeb();
20
19
  hasPatched = true;
@@ -33,19 +32,23 @@ function loader(source) {
33
32
  }
34
33
  const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`;
35
34
  const extracted = extractToClassNames({
36
- loader: this,
37
35
  extractor,
38
- cssLoaderPath: require.resolve("./css"),
39
36
  source,
40
- threaded,
41
37
  sourcePath,
42
- cssPath,
43
38
  options,
44
39
  shouldPrintDebug
45
40
  });
46
41
  if (!extracted) {
47
42
  return this.callback(null, source);
48
43
  }
44
+ if (extracted.styles) {
45
+ const cssQuery = threaded ? `cssData=${Buffer.from(extracted.styles).toString("base64")}` : `cssPath=${cssPath}`;
46
+ const remReq = this.remainingRequest;
47
+ const importPath = `${cssPath}!=!${CSS_LOADER_PATH}?${cssQuery}!${remReq}`;
48
+ extracted.js = `${extracted.js}
49
+
50
+ require(${JSON.stringify(importPath)})`;
51
+ }
49
52
  extractedInfoByFile.set(sourcePath, extracted);
50
53
  if (!threaded) {
51
54
  if (extracted.stylesPath) {
@@ -57,8 +60,8 @@ function loader(source) {
57
60
  console.error("ERROR", err);
58
61
  return this.callback(null, source);
59
62
  }
60
- }
61
- __name(loader, "loader");
63
+ };
62
64
  export {
63
65
  loader
64
66
  };
67
+ //# sourceMappingURL=loader.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/loader.ts"],
4
+ "sourcesContent": ["import {\n TamaguiOptions,\n createExtractor,\n extractToClassNames,\n patchReactNativeWeb,\n} from '@tamagui/static'\nimport type { LoaderContext, RawLoaderDefinitionFunction } from 'webpack'\n\nimport { extractedInfoByFile, stylePathToFilePath } from './css'\n\n// pass loader as path\nconst CSS_LOADER_PATH = require.resolve('./css')\n\nError.stackTraceLimit = Infinity\nconst extractor = createExtractor()\n\nlet index = 0\nlet hasPatched = false\n\nprocess.env.TAMAGUI_TARGET = 'web'\n\nexport const loader: RawLoaderDefinitionFunction<TamaguiOptions> = function loader(this, sourceIn) {\n this.cacheable(true)\n this.async()\n const source = sourceIn.toString()\n\n if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {\n patchReactNativeWeb()\n hasPatched = true\n }\n\n try {\n const threaded = this.emitFile === undefined\n const options: TamaguiOptions = { ...this.getOptions() }\n const sourcePath = `${this.resourcePath}`\n const startsWithComment = source[0] === '/' && source[1] === '/'\n\n let shouldPrintDebug: boolean | 'verbose' =\n (!!process.env.DEBUG &&\n (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true)) ||\n // supports esbuild style //! comments\n (startsWithComment && (source.startsWith('// debug') || source.startsWith('//! debug')))\n\n if (shouldPrintDebug && source.startsWith('// debug-verbose')) {\n shouldPrintDebug = 'verbose'\n }\n\n // check if should ignore\n if (\n startsWithComment &&\n (source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))\n ) {\n return this.callback(null, source)\n }\n\n const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`\n\n const extracted = extractToClassNames({\n extractor,\n source,\n sourcePath,\n options,\n shouldPrintDebug,\n })\n\n if (!extracted) {\n return this.callback(null, source)\n }\n\n // add import to css\n if (extracted.styles) {\n const cssQuery = threaded\n ? `cssData=${Buffer.from(extracted.styles).toString('base64')}`\n : `cssPath=${cssPath}`\n const remReq = this.remainingRequest\n const importPath = `${cssPath}!=!${CSS_LOADER_PATH}?${cssQuery}!${remReq}`\n extracted.js = `${extracted.js}\\n\\nrequire(${JSON.stringify(importPath)})`\n }\n\n extractedInfoByFile.set(sourcePath, extracted)\n\n if (!threaded) {\n if (extracted.stylesPath) {\n stylePathToFilePath.set(extracted.stylesPath, sourcePath)\n }\n }\n\n this.callback(null, extracted.js, extracted.map)\n } catch (err) {\n console.error('ERROR', err)\n return this.callback(null, source)\n }\n}\n"],
5
+ "mappings": "AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;AAGA,MAAM,kBAAkC;AAExC,MAAM,kBAAkB;AACxB,MAAM,YAAY,gBAAgB;AAElC,IAAI,QAAQ;AACZ,IAAI,aAAa;AAEjB,QAAQ,IAAI,iBAAiB;AAEtB,MAAM,SAAsD,iBAAsB,UAAU;AACjG,OAAK,UAAU,IAAI;AACnB,OAAK,MAAM;AACX,QAAM,SAAS,SAAS,SAAS;AAEjC,MAAI,CAAC,QAAQ,IAAI,6BAA6B,CAAC,YAAY;AACzD,wBAAoB;AACpB,iBAAa;AAAA,EACf;AAEA,MAAI;AACF,UAAM,WAAW,KAAK,aAAa;AACnC,UAAM,UAA0B,EAAE,GAAG,KAAK,WAAW,EAAE;AACvD,UAAM,aAAa,GAAG,KAAK;AAC3B,UAAM,oBAAoB,OAAO,OAAO,OAAO,OAAO,OAAO;AAE7D,QAAI,mBACD,CAAC,CAAC,QAAQ,IAAI,SACZ,SAAQ,IAAI,aAAa,WAAW,SAAS,QAAQ,IAAI,UAAU,IAAI,SAEzE,qBAAsB,QAAO,WAAW,UAAU,KAAK,OAAO,WAAW,WAAW;AAEvF,QAAI,oBAAoB,OAAO,WAAW,kBAAkB,GAAG;AAC7D,yBAAmB;AAAA,IACrB;AAGA,QACE,qBACC,QAAO,WAAW,mBAAmB,KAAK,OAAO,WAAW,oBAAoB,IACjF;AACA,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAEA,UAAM,UAAU,WAAW,GAAG,0BAA0B,GAAG,cAAc;AAEzE,UAAM,YAAY,oBAAoB;AAAA,MACpC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IACF,CAAC;AAED,QAAI,CAAC,WAAW;AACd,aAAO,KAAK,SAAS,MAAM,MAAM;AAAA,IACnC;AAGA,QAAI,UAAU,QAAQ;AACpB,YAAM,WAAW,WACb,WAAW,OAAO,KAAK,UAAU,MAAM,EAAE,SAAS,QAAQ,MAC1D,WAAW;AACf,YAAM,SAAS,KAAK;AACpB,YAAM,aAAa,GAAG,aAAa,mBAAmB,YAAY;AAClE,gBAAU,KAAK,GAAG,UAAU;AAAA;AAAA,UAAiB,KAAK,UAAU,UAAU;AAAA,IACxE;AAEA,wBAAoB,IAAI,YAAY,SAAS;AAE7C,QAAI,CAAC,UAAU;AACb,UAAI,UAAU,YAAY;AACxB,4BAAoB,IAAI,UAAU,YAAY,UAAU;AAAA,MAC1D;AAAA,IACF;AAEA,SAAK,SAAS,MAAM,UAAU,IAAI,UAAU,GAAG;AAAA,EACjD,SAAS,KAAP;AACA,YAAQ,MAAM,SAAS,GAAG;AAC1B,WAAO,KAAK,SAAS,MAAM,MAAM;AAAA,EACnC;AACF;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "tamagui-loader",
3
- "version": "1.0.0-beta.8",
4
- "typings": "types",
3
+ "version": "1.0.1-beta.100",
4
+ "types": "./types/index.d.ts",
5
5
  "main": "dist/cjs",
6
6
  "module": "dist/esm",
7
7
  "module:jsx": "dist/jsx",
8
8
  "files": [
9
+ "src",
9
10
  "types",
10
11
  "dist"
11
12
  ],
@@ -16,12 +17,12 @@
16
17
  "clean:build": "tamagui-build clean:build"
17
18
  },
18
19
  "dependencies": {
19
- "@tamagui/static": "^1.0.0-beta.8",
20
- "fs-extra": "^9.1.0",
20
+ "@tamagui/static": "^1.0.1-beta.100",
21
+ "fs-extra": "^10.1.0",
21
22
  "lodash": "^4.17.21"
22
23
  },
23
24
  "devDependencies": {
24
- "@tamagui/build": "^1.0.0-beta.8"
25
+ "@tamagui/build": "^1.0.1-beta.100"
25
26
  },
26
27
  "publishConfig": {
27
28
  "access": "public"
package/src/css.ts ADDED
@@ -0,0 +1,30 @@
1
+ import { ExtractedResponse, TamaguiOptions } from '@tamagui/static'
2
+ import { LoaderContext } from 'webpack'
3
+
4
+ export const extractedInfoByFile = new Map<string, ExtractedResponse>()
5
+ export const stylePathToFilePath = new Map<string, string>()
6
+
7
+ export default function loader(this: LoaderContext<any>) {
8
+ this.async()
9
+ const options: TamaguiOptions = { ...this.getOptions() }
10
+ const sourcePath = `${this.resourcePath}`
11
+ let out = ''
12
+ if (options.cssPath) {
13
+ // get in memory info
14
+ const pathKey = stylePathToFilePath.get(sourcePath) ?? sourcePath
15
+ const info = extractedInfoByFile.get(pathKey)
16
+ // clear memory
17
+ stylePathToFilePath.delete(sourcePath)
18
+ extractedInfoByFile.delete(pathKey)
19
+ const out = info?.styles
20
+ return this.callback(null, out || '')
21
+ } else if (options.cssData) {
22
+ // get output CSS
23
+ out = Buffer.from(options.cssData, 'base64').toString('utf-8')
24
+ }
25
+ if (out) {
26
+ // use original JS sourcemap
27
+ return this.callback(null, out || '')
28
+ }
29
+ this.callback({ message: `No CSS found`, name: 'missing_css' })
30
+ }
package/src/index.ts ADDED
@@ -0,0 +1,19 @@
1
+ process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || 'web'
2
+ process.env.TAMAGUI_COMPILE_PROCESS = '1'
3
+
4
+ export default require('./loader').loader
5
+
6
+ // helper for webpack exclude specific to tamagui
7
+
8
+ export const shouldExclude = (path: string, projectRoot: string) => {
9
+ if (
10
+ path.includes('react-native-reanimated') ||
11
+ path.includes('react-native-gesture-handler') ||
12
+ path.includes('@gorhom/portal') ||
13
+ path.includes(projectRoot) ||
14
+ path.includes('/dist/jsx/')
15
+ ) {
16
+ return false
17
+ }
18
+ return true
19
+ }
package/src/loader.ts ADDED
@@ -0,0 +1,93 @@
1
+ import {
2
+ TamaguiOptions,
3
+ createExtractor,
4
+ extractToClassNames,
5
+ patchReactNativeWeb,
6
+ } from '@tamagui/static'
7
+ import type { LoaderContext, RawLoaderDefinitionFunction } from 'webpack'
8
+
9
+ import { extractedInfoByFile, stylePathToFilePath } from './css'
10
+
11
+ // pass loader as path
12
+ const CSS_LOADER_PATH = require.resolve('./css')
13
+
14
+ Error.stackTraceLimit = Infinity
15
+ const extractor = createExtractor()
16
+
17
+ let index = 0
18
+ let hasPatched = false
19
+
20
+ process.env.TAMAGUI_TARGET = 'web'
21
+
22
+ export const loader: RawLoaderDefinitionFunction<TamaguiOptions> = function loader(this, sourceIn) {
23
+ this.cacheable(true)
24
+ this.async()
25
+ const source = sourceIn.toString()
26
+
27
+ if (!process.env.TAMAGUI_DISABLE_RNW_PATCH && !hasPatched) {
28
+ patchReactNativeWeb()
29
+ hasPatched = true
30
+ }
31
+
32
+ try {
33
+ const threaded = this.emitFile === undefined
34
+ const options: TamaguiOptions = { ...this.getOptions() }
35
+ const sourcePath = `${this.resourcePath}`
36
+ const startsWithComment = source[0] === '/' && source[1] === '/'
37
+
38
+ let shouldPrintDebug: boolean | 'verbose' =
39
+ (!!process.env.DEBUG &&
40
+ (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true)) ||
41
+ // supports esbuild style //! comments
42
+ (startsWithComment && (source.startsWith('// debug') || source.startsWith('//! debug')))
43
+
44
+ if (shouldPrintDebug && source.startsWith('// debug-verbose')) {
45
+ shouldPrintDebug = 'verbose'
46
+ }
47
+
48
+ // check if should ignore
49
+ if (
50
+ startsWithComment &&
51
+ (source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))
52
+ ) {
53
+ return this.callback(null, source)
54
+ }
55
+
56
+ const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`
57
+
58
+ const extracted = extractToClassNames({
59
+ extractor,
60
+ source,
61
+ sourcePath,
62
+ options,
63
+ shouldPrintDebug,
64
+ })
65
+
66
+ if (!extracted) {
67
+ return this.callback(null, source)
68
+ }
69
+
70
+ // add import to css
71
+ if (extracted.styles) {
72
+ const cssQuery = threaded
73
+ ? `cssData=${Buffer.from(extracted.styles).toString('base64')}`
74
+ : `cssPath=${cssPath}`
75
+ const remReq = this.remainingRequest
76
+ const importPath = `${cssPath}!=!${CSS_LOADER_PATH}?${cssQuery}!${remReq}`
77
+ extracted.js = `${extracted.js}\n\nrequire(${JSON.stringify(importPath)})`
78
+ }
79
+
80
+ extractedInfoByFile.set(sourcePath, extracted)
81
+
82
+ if (!threaded) {
83
+ if (extracted.stylesPath) {
84
+ stylePathToFilePath.set(extracted.stylesPath, sourcePath)
85
+ }
86
+ }
87
+
88
+ this.callback(null, extracted.js, extracted.map)
89
+ } catch (err) {
90
+ console.error('ERROR', err)
91
+ return this.callback(null, source)
92
+ }
93
+ }
package/types/css.d.ts CHANGED
@@ -2,5 +2,5 @@ import { ExtractedResponse } from '@tamagui/static';
2
2
  import { LoaderContext } from 'webpack';
3
3
  export declare const extractedInfoByFile: Map<string, ExtractedResponse>;
4
4
  export declare const stylePathToFilePath: Map<string, string>;
5
- export default function loader(this: LoaderContext<any>, source: string): void;
5
+ export default function loader(this: LoaderContext<any>): void;
6
6
  //# sourceMappingURL=css.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../src/css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkB,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,eAAO,MAAM,mBAAmB,gCAAuC,CAAA;AACvE,eAAO,MAAM,mBAAmB,qBAA4B,CAAA;AAE5D,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,QAuBtE"}
1
+ {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../src/css.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAkB,MAAM,iBAAiB,CAAA;AACnE,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAEvC,eAAO,MAAM,mBAAmB,gCAAuC,CAAA;AACvE,eAAO,MAAM,mBAAmB,qBAA4B,CAAA;AAE5D,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,QAuBtD"}
package/types/loader.d.ts CHANGED
@@ -1,3 +1,4 @@
1
- import { LoaderContext } from 'webpack';
2
- export declare function loader(this: LoaderContext<any>, source: string): void;
1
+ import { TamaguiOptions } from '@tamagui/static';
2
+ import type { RawLoaderDefinitionFunction } from 'webpack';
3
+ export declare const loader: RawLoaderDefinitionFunction<TamaguiOptions>;
3
4
  //# sourceMappingURL=loader.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAavC,wBAAgB,MAAM,CAAC,IAAI,EAAE,aAAa,CAAC,GAAG,CAAC,EAAE,MAAM,EAAE,MAAM,QAgE9D"}
1
+ {"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAIf,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAiB,2BAA2B,EAAE,MAAM,SAAS,CAAA;AAezE,eAAO,MAAM,MAAM,EAAE,2BAA2B,CAAC,cAAc,CAuE9D,CAAA"}
package/types/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- declare const _default: any;
2
- export default _default;
3
- export declare const shouldExclude: (path: string, projectRoot: string, tamaguiOptions: any) => boolean;
4
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAGA,wBAAyC;AAIzC,eAAO,MAAM,aAAa,SAAU,MAAM,eAAe,MAAM,kBAAkB,GAAG,YAWnF,CAAA"}