tamagui-loader 1.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +130 -0
- package/dist/index.cjs.map +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +7 -0
- package/dist/loader.js +79 -0
- package/dist/loader.js.map +7 -0
- package/package.json +29 -0
- package/src/index.ts +4 -0
- package/src/loader.ts +104 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
10
|
+
var __spreadValues = (a, b) => {
|
|
11
|
+
for (var prop in b || (b = {}))
|
|
12
|
+
if (__hasOwnProp.call(b, prop))
|
|
13
|
+
__defNormalProp(a, prop, b[prop]);
|
|
14
|
+
if (__getOwnPropSymbols)
|
|
15
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
16
|
+
if (__propIsEnum.call(b, prop))
|
|
17
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
|
+
}
|
|
19
|
+
return a;
|
|
20
|
+
};
|
|
21
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
22
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
23
|
+
var __esm = (fn, res) => function __init() {
|
|
24
|
+
return fn && (res = (0, fn[Object.keys(fn)[0]])(fn = 0)), res;
|
|
25
|
+
};
|
|
26
|
+
var __export = (target, all) => {
|
|
27
|
+
__markAsModule(target);
|
|
28
|
+
for (var name in all)
|
|
29
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
30
|
+
};
|
|
31
|
+
var __reExport = (target, module2, desc) => {
|
|
32
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
33
|
+
for (let key of __getOwnPropNames(module2))
|
|
34
|
+
if (!__hasOwnProp.call(target, key) && key !== "default")
|
|
35
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
36
|
+
}
|
|
37
|
+
return target;
|
|
38
|
+
};
|
|
39
|
+
var __toModule = (module2) => {
|
|
40
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// src/loader.ts
|
|
44
|
+
var loader_exports = {};
|
|
45
|
+
__export(loader_exports, {
|
|
46
|
+
loader: () => loader
|
|
47
|
+
});
|
|
48
|
+
function loader(source) {
|
|
49
|
+
this.cacheable();
|
|
50
|
+
const callback = this.async();
|
|
51
|
+
if (!process.env.TAMAGUI_DISABLE_RNW_PATCH) {
|
|
52
|
+
(0, import_static.patchReactNativeWeb)();
|
|
53
|
+
}
|
|
54
|
+
try {
|
|
55
|
+
const threaded = this.emitFile === void 0;
|
|
56
|
+
const options = __spreadValues({}, (0, import_loader_utils.getOptions)(this));
|
|
57
|
+
if (options.disableExtraction) {
|
|
58
|
+
if (!hasLogged) {
|
|
59
|
+
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
60
|
+
hasLogged = true;
|
|
61
|
+
}
|
|
62
|
+
return callback(null, source);
|
|
63
|
+
}
|
|
64
|
+
const sourcePath = `${this.resourcePath}`;
|
|
65
|
+
const startsWithComment = source[0] === "/" && source[1] === "/";
|
|
66
|
+
const shouldPrintDebug = !!process.env.DEBUG && (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true) || startsWithComment && (source.startsWith("// debug") || source.startsWith("//! debug"));
|
|
67
|
+
if (options.cssPath || options.cssData) {
|
|
68
|
+
const out = options.cssData ? Buffer.from(options.cssData, "base64").toString("utf-8") : stylesByFile.get(stylePathToFilePath.get(sourcePath) ?? sourcePath);
|
|
69
|
+
if (!out) {
|
|
70
|
+
console.warn(`no styles... ${stylesByFile.keys} ${sourcePath}`);
|
|
71
|
+
}
|
|
72
|
+
return callback(null, out);
|
|
73
|
+
}
|
|
74
|
+
const isTamaguiInternalView = sourcePath.includes("/tamagui/");
|
|
75
|
+
if (!isTamaguiInternalView && ((0, import_path.extname)(sourcePath) !== ".tsx" || startsWithComment && (source.startsWith("// tamagui-ignore") || source.startsWith("//! tamagui-ignore")))) {
|
|
76
|
+
return callback(null, source);
|
|
77
|
+
}
|
|
78
|
+
const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`;
|
|
79
|
+
const extracted = (0, import_static.extractToClassNames)({
|
|
80
|
+
loader: this,
|
|
81
|
+
extractor,
|
|
82
|
+
source,
|
|
83
|
+
threaded,
|
|
84
|
+
sourcePath,
|
|
85
|
+
cssPath,
|
|
86
|
+
options,
|
|
87
|
+
shouldPrintDebug
|
|
88
|
+
});
|
|
89
|
+
if (!extracted) {
|
|
90
|
+
return callback(null, source);
|
|
91
|
+
}
|
|
92
|
+
if (!threaded) {
|
|
93
|
+
if (extracted.stylesPath) {
|
|
94
|
+
stylePathToFilePath.set(extracted.stylesPath, sourcePath);
|
|
95
|
+
}
|
|
96
|
+
if (extracted.styles) {
|
|
97
|
+
stylesByFile.set(sourcePath, extracted.styles);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
callback(null, extracted.js, extracted.map);
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error("ERROR", err);
|
|
103
|
+
return callback(null, source);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
var import_path, import_static, import_loader_utils, extractor, stylesByFile, stylePathToFilePath, index, hasLogged;
|
|
107
|
+
var init_loader = __esm({
|
|
108
|
+
"src/loader.ts"() {
|
|
109
|
+
import_path = __toModule(require("path"));
|
|
110
|
+
import_static = __toModule(require("@tamagui/static"));
|
|
111
|
+
import_loader_utils = __toModule(require("loader-utils"));
|
|
112
|
+
Error.stackTraceLimit = Infinity;
|
|
113
|
+
extractor = (0, import_static.createExtractor)();
|
|
114
|
+
stylesByFile = new Map();
|
|
115
|
+
stylePathToFilePath = new Map();
|
|
116
|
+
index = 0;
|
|
117
|
+
hasLogged = false;
|
|
118
|
+
process.env.TAMAGUI_TARGET = "web";
|
|
119
|
+
__name(loader, "loader");
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// src/index.ts
|
|
124
|
+
__export(exports, {
|
|
125
|
+
default: () => src_default
|
|
126
|
+
});
|
|
127
|
+
process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || "web";
|
|
128
|
+
process.env.TAMAGUI_COMPILE_PROCESS = "1";
|
|
129
|
+
var src_default = (init_loader(), loader_exports).loader;
|
|
130
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/loader.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": ["import { extname } from 'path'\n\nimport {\n TamaguiOptions,\n createExtractor,\n extractToClassNames,\n patchReactNativeWeb,\n} from '@tamagui/static'\nimport { getOptions } from 'loader-utils'\n\nError.stackTraceLimit = Infinity\nconst extractor = createExtractor()\n\nconst stylesByFile = new Map<string, string>()\nconst stylePathToFilePath = new Map<string, string>()\n\nlet index = 0\nlet hasLogged = false\n\nprocess.env.TAMAGUI_TARGET = 'web'\n\nexport function loader(this: any, source: string) {\n this.cacheable()\n const callback = this.async()\n\n if (!process.env.TAMAGUI_DISABLE_RNW_PATCH) {\n patchReactNativeWeb()\n }\n\n try {\n const threaded = this.emitFile === undefined\n const options: TamaguiOptions = { ...getOptions(this) }\n\n if (options.disableExtraction) {\n if (!hasLogged) {\n console.log('\uD83E\uDD5A Tamagui disableExtraction set: no CSS or optimizations will be run')\n hasLogged = true\n }\n return callback(null, source)\n }\n\n const sourcePath = `${this.resourcePath}`\n const startsWithComment = source[0] === '/' && source[1] === '/'\n const shouldPrintDebug =\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 outputted css\n if (options.cssPath || options.cssData) {\n const out = options.cssData\n ? Buffer.from(options.cssData, 'base64').toString('utf-8')\n : stylesByFile.get(stylePathToFilePath.get(sourcePath) ?? sourcePath)\n if (!out) {\n console.warn(`no styles... ${stylesByFile.keys} ${sourcePath}`)\n }\n return callback(null, out)\n }\n\n // check if should ignore\n const isTamaguiInternalView = sourcePath.includes('/tamagui/')\n\n if (\n !isTamaguiInternalView &&\n (extname(sourcePath) !== '.tsx' ||\n (startsWithComment &&\n (source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))))\n ) {\n return callback(null, source)\n }\n\n const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`\n const extracted = extractToClassNames({\n // @ts-ignore\n loader: this,\n extractor,\n source,\n threaded,\n sourcePath,\n cssPath,\n options,\n shouldPrintDebug,\n })\n\n if (!extracted) {\n return callback(null, source)\n }\n\n if (!threaded) {\n if (extracted.stylesPath) {\n stylePathToFilePath.set(extracted.stylesPath, sourcePath)\n }\n if (extracted.styles) {\n stylesByFile.set(sourcePath, extracted.styles)\n }\n }\n\n callback(null, extracted.js, extracted.map)\n } catch (err) {\n console.error('ERROR', err)\n return callback(null, source)\n }\n}\n", "process.env.TAMAGUI_TARGET = process.env.TAMAGUI_TARGET || 'web'\nprocess.env.TAMAGUI_COMPILE_PROCESS = '1'\n\nexport default require('./loader').loader\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAqBO,gBAA2B,QAAgB;AAChD,OAAK;AACL,QAAM,WAAW,KAAK;AAEtB,MAAI,CAAC,QAAQ,IAAI,2BAA2B;AAC1C;AAAA;AAGF,MAAI;AACF,UAAM,WAAW,KAAK,aAAa;AACnC,UAAM,UAA0B,mBAAK,oCAAW;AAEhD,QAAI,QAAQ,mBAAmB;AAC7B,UAAI,CAAC,WAAW;AACd,gBAAQ,IAAI;AACZ,oBAAY;AAAA;AAEd,aAAO,SAAS,MAAM;AAAA;AAGxB,UAAM,aAAa,GAAG,KAAK;AAC3B,UAAM,oBAAoB,OAAO,OAAO,OAAO,OAAO,OAAO;AAC7D,UAAM,mBACH,CAAC,CAAC,QAAQ,IAAI,SACZ,SAAQ,IAAI,aAAa,WAAW,SAAS,QAAQ,IAAI,cAAc,SAEzE,qBAAsB,QAAO,WAAW,eAAe,OAAO,WAAW;AAG5E,QAAI,QAAQ,WAAW,QAAQ,SAAS;AACtC,YAAM,MAAM,QAAQ,UAChB,OAAO,KAAK,QAAQ,SAAS,UAAU,SAAS,WAChD,aAAa,IAAI,oBAAoB,IAAI,eAAe;AAC5D,UAAI,CAAC,KAAK;AACR,gBAAQ,KAAK,gBAAgB,aAAa,QAAQ;AAAA;AAEpD,aAAO,SAAS,MAAM;AAAA;AAIxB,UAAM,wBAAwB,WAAW,SAAS;AAElD,QACE,CAAC,yBACA,0BAAQ,gBAAgB,UACtB,qBACE,QAAO,WAAW,wBAAwB,OAAO,WAAW,yBACjE;AACA,aAAO,SAAS,MAAM;AAAA;AAGxB,UAAM,UAAU,WAAW,GAAG,0BAA0B,GAAG,cAAc;AACzE,UAAM,YAAY,uCAAoB;AAAA,MAEpC,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAGF,QAAI,CAAC,WAAW;AACd,aAAO,SAAS,MAAM;AAAA;AAGxB,QAAI,CAAC,UAAU;AACb,UAAI,UAAU,YAAY;AACxB,4BAAoB,IAAI,UAAU,YAAY;AAAA;AAEhD,UAAI,UAAU,QAAQ;AACpB,qBAAa,IAAI,YAAY,UAAU;AAAA;AAAA;AAI3C,aAAS,MAAM,UAAU,IAAI,UAAU;AAAA,WAChC,KAAP;AACA,YAAQ,MAAM,SAAS;AACvB,WAAO,SAAS,MAAM;AAAA;AAAA;AArG1B,iBAEA,eAMA,qBAGM,WAEA,cACA,qBAEF,OACA;AAjBJ;AAAA;AAAA,kBAAwB;AAExB,oBAKO;AACP,0BAA2B;AAE3B,UAAM,kBAAkB;AACxB,IAAM,YAAY;AAElB,IAAM,eAAe,IAAI;AACzB,IAAM,sBAAsB,IAAI;AAEhC,IAAI,QAAQ;AACZ,IAAI,YAAY;AAEhB,YAAQ,IAAI,iBAAiB;AAEb;AAAA;AAAA;;;ACrBhB;AAAA;AAAA;AAAA,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB;AAC3D,QAAQ,IAAI,0BAA0B;AAEtC,IAAO,cAAQ,gCAAoB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/index.js
ADDED
|
@@ -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"],
|
|
5
|
+
"mappings": "AAAA,QAAQ,IAAI,iBAAiB,QAAQ,IAAI,kBAAkB;AAC3D,QAAQ,IAAI,0BAA0B;AAEtC,IAAO,cAAQ,QAAQ,YAAY;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/loader.js
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
import { extname } from "path";
|
|
4
|
+
import {
|
|
5
|
+
createExtractor,
|
|
6
|
+
extractToClassNames,
|
|
7
|
+
patchReactNativeWeb
|
|
8
|
+
} from "@tamagui/static";
|
|
9
|
+
import { getOptions } from "loader-utils";
|
|
10
|
+
Error.stackTraceLimit = Infinity;
|
|
11
|
+
const extractor = createExtractor();
|
|
12
|
+
const stylesByFile = new Map();
|
|
13
|
+
const stylePathToFilePath = new Map();
|
|
14
|
+
let index = 0;
|
|
15
|
+
let hasLogged = false;
|
|
16
|
+
process.env.TAMAGUI_TARGET = "web";
|
|
17
|
+
function loader(source) {
|
|
18
|
+
this.cacheable();
|
|
19
|
+
const callback = this.async();
|
|
20
|
+
if (!process.env.TAMAGUI_DISABLE_RNW_PATCH) {
|
|
21
|
+
patchReactNativeWeb();
|
|
22
|
+
}
|
|
23
|
+
try {
|
|
24
|
+
const threaded = this.emitFile === void 0;
|
|
25
|
+
const options = { ...getOptions(this) };
|
|
26
|
+
if (options.disableExtraction) {
|
|
27
|
+
if (!hasLogged) {
|
|
28
|
+
console.log("\u{1F95A} Tamagui disableExtraction set: no CSS or optimizations will be run");
|
|
29
|
+
hasLogged = true;
|
|
30
|
+
}
|
|
31
|
+
return callback(null, source);
|
|
32
|
+
}
|
|
33
|
+
const sourcePath = `${this.resourcePath}`;
|
|
34
|
+
const startsWithComment = source[0] === "/" && source[1] === "/";
|
|
35
|
+
const shouldPrintDebug = !!process.env.DEBUG && (process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true) || startsWithComment && (source.startsWith("// debug") || source.startsWith("//! debug"));
|
|
36
|
+
if (options.cssPath || options.cssData) {
|
|
37
|
+
const out = options.cssData ? Buffer.from(options.cssData, "base64").toString("utf-8") : stylesByFile.get(stylePathToFilePath.get(sourcePath) ?? sourcePath);
|
|
38
|
+
if (!out) {
|
|
39
|
+
console.warn(`no styles... ${stylesByFile.keys} ${sourcePath}`);
|
|
40
|
+
}
|
|
41
|
+
return callback(null, out);
|
|
42
|
+
}
|
|
43
|
+
const isTamaguiInternalView = sourcePath.includes("/tamagui/");
|
|
44
|
+
if (!isTamaguiInternalView && (extname(sourcePath) !== ".tsx" || startsWithComment && (source.startsWith("// tamagui-ignore") || source.startsWith("//! tamagui-ignore")))) {
|
|
45
|
+
return callback(null, source);
|
|
46
|
+
}
|
|
47
|
+
const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`;
|
|
48
|
+
const extracted = extractToClassNames({
|
|
49
|
+
loader: this,
|
|
50
|
+
extractor,
|
|
51
|
+
source,
|
|
52
|
+
threaded,
|
|
53
|
+
sourcePath,
|
|
54
|
+
cssPath,
|
|
55
|
+
options,
|
|
56
|
+
shouldPrintDebug
|
|
57
|
+
});
|
|
58
|
+
if (!extracted) {
|
|
59
|
+
return callback(null, source);
|
|
60
|
+
}
|
|
61
|
+
if (!threaded) {
|
|
62
|
+
if (extracted.stylesPath) {
|
|
63
|
+
stylePathToFilePath.set(extracted.stylesPath, sourcePath);
|
|
64
|
+
}
|
|
65
|
+
if (extracted.styles) {
|
|
66
|
+
stylesByFile.set(sourcePath, extracted.styles);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
callback(null, extracted.js, extracted.map);
|
|
70
|
+
} catch (err) {
|
|
71
|
+
console.error("ERROR", err);
|
|
72
|
+
return callback(null, source);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
__name(loader, "loader");
|
|
76
|
+
export {
|
|
77
|
+
loader
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/loader.ts"],
|
|
4
|
+
"sourcesContent": ["import { extname } from 'path'\n\nimport {\n TamaguiOptions,\n createExtractor,\n extractToClassNames,\n patchReactNativeWeb,\n} from '@tamagui/static'\nimport { getOptions } from 'loader-utils'\n\nError.stackTraceLimit = Infinity\nconst extractor = createExtractor()\n\nconst stylesByFile = new Map<string, string>()\nconst stylePathToFilePath = new Map<string, string>()\n\nlet index = 0\nlet hasLogged = false\n\nprocess.env.TAMAGUI_TARGET = 'web'\n\nexport function loader(this: any, source: string) {\n this.cacheable()\n const callback = this.async()\n\n if (!process.env.TAMAGUI_DISABLE_RNW_PATCH) {\n patchReactNativeWeb()\n }\n\n try {\n const threaded = this.emitFile === undefined\n const options: TamaguiOptions = { ...getOptions(this) }\n\n if (options.disableExtraction) {\n if (!hasLogged) {\n console.log('\uD83E\uDD5A Tamagui disableExtraction set: no CSS or optimizations will be run')\n hasLogged = true\n }\n return callback(null, source)\n }\n\n const sourcePath = `${this.resourcePath}`\n const startsWithComment = source[0] === '/' && source[1] === '/'\n const shouldPrintDebug =\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 outputted css\n if (options.cssPath || options.cssData) {\n const out = options.cssData\n ? Buffer.from(options.cssData, 'base64').toString('utf-8')\n : stylesByFile.get(stylePathToFilePath.get(sourcePath) ?? sourcePath)\n if (!out) {\n console.warn(`no styles... ${stylesByFile.keys} ${sourcePath}`)\n }\n return callback(null, out)\n }\n\n // check if should ignore\n const isTamaguiInternalView = sourcePath.includes('/tamagui/')\n\n if (\n !isTamaguiInternalView &&\n (extname(sourcePath) !== '.tsx' ||\n (startsWithComment &&\n (source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))))\n ) {\n return callback(null, source)\n }\n\n const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`\n const extracted = extractToClassNames({\n // @ts-ignore\n loader: this,\n extractor,\n source,\n threaded,\n sourcePath,\n cssPath,\n options,\n shouldPrintDebug,\n })\n\n if (!extracted) {\n return callback(null, source)\n }\n\n if (!threaded) {\n if (extracted.stylesPath) {\n stylePathToFilePath.set(extracted.stylesPath, sourcePath)\n }\n if (extracted.styles) {\n stylesByFile.set(sourcePath, extracted.styles)\n }\n }\n\n callback(null, extracted.js, extracted.map)\n } catch (err) {\n console.error('ERROR', err)\n return callback(null, source)\n }\n}\n"],
|
|
5
|
+
"mappings": ";;AAAA;AAEA;AAAA;AAAA;AAAA;AAAA;AAMA;AAEA,MAAM,kBAAkB;AACxB,MAAM,YAAY;AAElB,MAAM,eAAe,IAAI;AACzB,MAAM,sBAAsB,IAAI;AAEhC,IAAI,QAAQ;AACZ,IAAI,YAAY;AAEhB,QAAQ,IAAI,iBAAiB;AAEtB,gBAA2B,QAAgB;AAChD,OAAK;AACL,QAAM,WAAW,KAAK;AAEtB,MAAI,CAAC,QAAQ,IAAI,2BAA2B;AAC1C;AAAA;AAGF,MAAI;AACF,UAAM,WAAW,KAAK,aAAa;AACnC,UAAM,UAA0B,KAAK,WAAW;AAEhD,QAAI,QAAQ,mBAAmB;AAC7B,UAAI,CAAC,WAAW;AACd,gBAAQ,IAAI;AACZ,oBAAY;AAAA;AAEd,aAAO,SAAS,MAAM;AAAA;AAGxB,UAAM,aAAa,GAAG,KAAK;AAC3B,UAAM,oBAAoB,OAAO,OAAO,OAAO,OAAO,OAAO;AAC7D,UAAM,mBACH,CAAC,CAAC,QAAQ,IAAI,SACZ,SAAQ,IAAI,aAAa,WAAW,SAAS,QAAQ,IAAI,cAAc,SAEzE,qBAAsB,QAAO,WAAW,eAAe,OAAO,WAAW;AAG5E,QAAI,QAAQ,WAAW,QAAQ,SAAS;AACtC,YAAM,MAAM,QAAQ,UAChB,OAAO,KAAK,QAAQ,SAAS,UAAU,SAAS,WAChD,aAAa,IAAI,oBAAoB,IAAI,eAAe;AAC5D,UAAI,CAAC,KAAK;AACR,gBAAQ,KAAK,gBAAgB,aAAa,QAAQ;AAAA;AAEpD,aAAO,SAAS,MAAM;AAAA;AAIxB,UAAM,wBAAwB,WAAW,SAAS;AAElD,QACE,CAAC,yBACA,SAAQ,gBAAgB,UACtB,qBACE,QAAO,WAAW,wBAAwB,OAAO,WAAW,yBACjE;AACA,aAAO,SAAS,MAAM;AAAA;AAGxB,UAAM,UAAU,WAAW,GAAG,0BAA0B,GAAG,cAAc;AACzE,UAAM,YAAY,oBAAoB;AAAA,MAEpC,QAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAGF,QAAI,CAAC,WAAW;AACd,aAAO,SAAS,MAAM;AAAA;AAGxB,QAAI,CAAC,UAAU;AACb,UAAI,UAAU,YAAY;AACxB,4BAAoB,IAAI,UAAU,YAAY;AAAA;AAEhD,UAAI,UAAU,QAAQ;AACpB,qBAAa,IAAI,YAAY,UAAU;AAAA;AAAA;AAI3C,aAAS,MAAM,UAAU,IAAI,UAAU;AAAA,WAChC,KAAP;AACA,YAAQ,MAAM,SAAS;AACvB,WAAO,SAAS,MAAM;AAAA;AAAA;AAhFV;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "tamagui-loader",
|
|
3
|
+
"version": "1.0.0-alpha.0",
|
|
4
|
+
"source": "src/index.ts",
|
|
5
|
+
"main": "dist/index.cjs",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"typings": "types.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist",
|
|
10
|
+
"src"
|
|
11
|
+
],
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tamagui-build",
|
|
14
|
+
"watch": "tamagui-build --watch"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@tamagui/static": "^1.0.0-alpha.0",
|
|
18
|
+
"fs-extra": "^9.1.0",
|
|
19
|
+
"loader-utils": "^2.0.0",
|
|
20
|
+
"lodash": "^4.17.21"
|
|
21
|
+
},
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"@tamagui/build": "^1.0.0-alpha.0"
|
|
24
|
+
},
|
|
25
|
+
"publishConfig": {
|
|
26
|
+
"access": "public"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "a41c5a5b08be5518d138515137122c248e3f7c71"
|
|
29
|
+
}
|
package/src/index.ts
ADDED
package/src/loader.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { extname } from 'path'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
TamaguiOptions,
|
|
5
|
+
createExtractor,
|
|
6
|
+
extractToClassNames,
|
|
7
|
+
patchReactNativeWeb,
|
|
8
|
+
} from '@tamagui/static'
|
|
9
|
+
import { getOptions } from 'loader-utils'
|
|
10
|
+
|
|
11
|
+
Error.stackTraceLimit = Infinity
|
|
12
|
+
const extractor = createExtractor()
|
|
13
|
+
|
|
14
|
+
const stylesByFile = new Map<string, string>()
|
|
15
|
+
const stylePathToFilePath = new Map<string, string>()
|
|
16
|
+
|
|
17
|
+
let index = 0
|
|
18
|
+
let hasLogged = false
|
|
19
|
+
|
|
20
|
+
process.env.TAMAGUI_TARGET = 'web'
|
|
21
|
+
|
|
22
|
+
export function loader(this: any, source: string) {
|
|
23
|
+
this.cacheable()
|
|
24
|
+
const callback = this.async()
|
|
25
|
+
|
|
26
|
+
if (!process.env.TAMAGUI_DISABLE_RNW_PATCH) {
|
|
27
|
+
patchReactNativeWeb()
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const threaded = this.emitFile === undefined
|
|
32
|
+
const options: TamaguiOptions = { ...getOptions(this) }
|
|
33
|
+
|
|
34
|
+
if (options.disableExtraction) {
|
|
35
|
+
if (!hasLogged) {
|
|
36
|
+
console.log('🥚 Tamagui disableExtraction set: no CSS or optimizations will be run')
|
|
37
|
+
hasLogged = true
|
|
38
|
+
}
|
|
39
|
+
return callback(null, source)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const sourcePath = `${this.resourcePath}`
|
|
43
|
+
const startsWithComment = source[0] === '/' && source[1] === '/'
|
|
44
|
+
const shouldPrintDebug =
|
|
45
|
+
(!!process.env.DEBUG &&
|
|
46
|
+
(process.env.DEBUG_FILE ? sourcePath.includes(process.env.DEBUG_FILE) : true)) ||
|
|
47
|
+
// supports esbuild style //! comments
|
|
48
|
+
(startsWithComment && (source.startsWith('// debug') || source.startsWith('//! debug')))
|
|
49
|
+
|
|
50
|
+
// if outputted css
|
|
51
|
+
if (options.cssPath || options.cssData) {
|
|
52
|
+
const out = options.cssData
|
|
53
|
+
? Buffer.from(options.cssData, 'base64').toString('utf-8')
|
|
54
|
+
: stylesByFile.get(stylePathToFilePath.get(sourcePath) ?? sourcePath)
|
|
55
|
+
if (!out) {
|
|
56
|
+
console.warn(`no styles... ${stylesByFile.keys} ${sourcePath}`)
|
|
57
|
+
}
|
|
58
|
+
return callback(null, out)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// check if should ignore
|
|
62
|
+
const isTamaguiInternalView = sourcePath.includes('/tamagui/')
|
|
63
|
+
|
|
64
|
+
if (
|
|
65
|
+
!isTamaguiInternalView &&
|
|
66
|
+
(extname(sourcePath) !== '.tsx' ||
|
|
67
|
+
(startsWithComment &&
|
|
68
|
+
(source.startsWith('// tamagui-ignore') || source.startsWith('//! tamagui-ignore'))))
|
|
69
|
+
) {
|
|
70
|
+
return callback(null, source)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const cssPath = threaded ? `${sourcePath}.module.css` : `${sourcePath}.${index++}.module.css`
|
|
74
|
+
const extracted = extractToClassNames({
|
|
75
|
+
// @ts-ignore
|
|
76
|
+
loader: this,
|
|
77
|
+
extractor,
|
|
78
|
+
source,
|
|
79
|
+
threaded,
|
|
80
|
+
sourcePath,
|
|
81
|
+
cssPath,
|
|
82
|
+
options,
|
|
83
|
+
shouldPrintDebug,
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
if (!extracted) {
|
|
87
|
+
return callback(null, source)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (!threaded) {
|
|
91
|
+
if (extracted.stylesPath) {
|
|
92
|
+
stylePathToFilePath.set(extracted.stylesPath, sourcePath)
|
|
93
|
+
}
|
|
94
|
+
if (extracted.styles) {
|
|
95
|
+
stylesByFile.set(sourcePath, extracted.styles)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
callback(null, extracted.js, extracted.map)
|
|
100
|
+
} catch (err) {
|
|
101
|
+
console.error('ERROR', err)
|
|
102
|
+
return callback(null, source)
|
|
103
|
+
}
|
|
104
|
+
}
|