@wyw-in-js/esbuild 0.1.1 → 0.2.1
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/README.md +35 -0
- package/esm/index.js +6 -6
- package/esm/index.js.map +1 -1
- package/lib/index.js +6 -6
- package/lib/index.js.map +1 -1
- package/package.json +7 -7
- package/types/index.js +6 -6
package/README.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# @wyw-in-js/esbuild
|
|
2
|
+
|
|
3
|
+
The package contains WyW-in-JS plugin for [esbuild](https://esbuild.github.io/).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```shell
|
|
8
|
+
# npm
|
|
9
|
+
npm i -D @wyw-in-js/esbuild
|
|
10
|
+
# yarn
|
|
11
|
+
yarn add --dev @wyw-in-js/esbuild
|
|
12
|
+
# pnpm
|
|
13
|
+
pnpm add -D @wyw-in-js/esbuild
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```js
|
|
19
|
+
import wyw from '@wyw-in-js/esbuild';
|
|
20
|
+
import esbuild from 'esbuild';
|
|
21
|
+
|
|
22
|
+
const isProduction = process.env.NODE_ENV === 'production';
|
|
23
|
+
|
|
24
|
+
esbuild
|
|
25
|
+
.build({
|
|
26
|
+
entryPoints: ['src/index.ts'],
|
|
27
|
+
outdir: 'dist',
|
|
28
|
+
bundle: true,
|
|
29
|
+
minify: isProduction,
|
|
30
|
+
plugins: [wyw({ sourceMap: isProduction })],
|
|
31
|
+
})
|
|
32
|
+
.catch(() => process.exit(1));
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
To get details about supported options by the plugin, please check [documentation](https://wyw-in-js.dev/bundlers/esbuild).
|
package/esm/index.js
CHANGED
|
@@ -33,16 +33,16 @@ export default function wywInJS({
|
|
|
33
33
|
return result.path.replace(/\\/g, posix.sep);
|
|
34
34
|
};
|
|
35
35
|
build.onResolve({
|
|
36
|
-
filter: /\.
|
|
36
|
+
filter: /\.wyw\.css$/
|
|
37
37
|
}, args => {
|
|
38
38
|
return {
|
|
39
|
-
namespace: '
|
|
39
|
+
namespace: 'wyw-in-js',
|
|
40
40
|
path: args.path
|
|
41
41
|
};
|
|
42
42
|
});
|
|
43
43
|
build.onLoad({
|
|
44
44
|
filter: /.*/,
|
|
45
|
-
namespace: '
|
|
45
|
+
namespace: 'wyw-in-js'
|
|
46
46
|
}, args => {
|
|
47
47
|
return {
|
|
48
48
|
contents: cssLookup.get(args.path),
|
|
@@ -108,13 +108,13 @@ export default function wywInJS({
|
|
|
108
108
|
cssText
|
|
109
109
|
} = result;
|
|
110
110
|
const slug = slugify(cssText);
|
|
111
|
-
const cssFilename = `${filename}_${slug}.
|
|
111
|
+
const cssFilename = `${filename}_${slug}.wyw.css`;
|
|
112
112
|
let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
|
|
113
113
|
if (sourceMap && result.cssSourceMapText) {
|
|
114
114
|
const map = Buffer.from(result.cssSourceMapText).toString('base64');
|
|
115
115
|
cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
116
|
-
const
|
|
117
|
-
contents += `/*# sourceMappingURL=data:application/json;base64,${
|
|
116
|
+
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
117
|
+
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
118
118
|
}
|
|
119
119
|
cssLookup.set(cssFilename, cssText);
|
|
120
120
|
return {
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["readFileSync","basename","dirname","isAbsolute","join","parse","posix","transformSync","slugify","transform","TransformCacheCollection","nodeModulesRegex","wywInJS","sourceMap","preprocessor","esbuildOptions","rest","options","cache","name","setup","build","cssLookup","Map","asyncResolve","token","importer","context","process","cwd","result","resolve","resolveDir","kind","errors","length","Error","path","replace","sep","onResolve","filter","args","namespace","onLoad","contents","get","loader","rawCode","ext","filename","test","initialOptions","jsxFactory","jsxFragment","transformed","sourcefile","sourcemap","code","esbuildMap","Buffer","from","map","toString","transformServices","root","pluginOptions","cssText","slug","cssFilename","JSON","stringify","cssSourceMapText","
|
|
1
|
+
{"version":3,"file":"index.js","names":["readFileSync","basename","dirname","isAbsolute","join","parse","posix","transformSync","slugify","transform","TransformCacheCollection","nodeModulesRegex","wywInJS","sourceMap","preprocessor","esbuildOptions","rest","options","cache","name","setup","build","cssLookup","Map","asyncResolve","token","importer","context","process","cwd","result","resolve","resolveDir","kind","errors","length","Error","path","replace","sep","onResolve","filter","args","namespace","onLoad","contents","get","loader","rawCode","ext","filename","test","initialOptions","jsxFactory","jsxFragment","transformed","sourcefile","sourcemap","code","esbuildMap","Buffer","from","map","toString","transformServices","root","pluginOptions","cssText","slug","cssFilename","JSON","stringify","cssSourceMapText","wywMap","set"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * This file contains an esbuild loader for wyw-in-js.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport { readFileSync } from 'fs';\nimport { basename, dirname, isAbsolute, join, parse, posix } from 'path';\n\nimport type { Plugin, TransformOptions, Loader } from 'esbuild';\nimport { transformSync } from 'esbuild';\n\nimport type { PluginOptions, Preprocessor } from '@wyw-in-js/transform';\nimport {\n slugify,\n transform,\n TransformCacheCollection,\n} from '@wyw-in-js/transform';\n\ntype EsbuildPluginOptions = {\n esbuildOptions?: TransformOptions;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n} & Partial<PluginOptions>;\n\nconst nodeModulesRegex = /^(?:.*[\\\\/])?node_modules(?:[\\\\/].*)?$/;\n\nexport default function wywInJS({\n sourceMap,\n preprocessor,\n esbuildOptions,\n ...rest\n}: EsbuildPluginOptions = {}): Plugin {\n let options = esbuildOptions;\n const cache = new TransformCacheCollection();\n return {\n name: 'wyw-in-js',\n setup(build) {\n const cssLookup = new Map<string, string>();\n\n const asyncResolve = async (\n token: string,\n importer: string\n ): Promise<string> => {\n const context = isAbsolute(importer)\n ? dirname(importer)\n : join(process.cwd(), dirname(importer));\n\n const result = await build.resolve(token, {\n resolveDir: context,\n kind: 'import-statement',\n });\n\n if (result.errors.length > 0) {\n throw new Error(`Cannot resolve ${token}`);\n }\n\n return result.path.replace(/\\\\/g, posix.sep);\n };\n\n build.onResolve({ filter: /\\.wyw\\.css$/ }, (args) => {\n return {\n namespace: 'wyw-in-js',\n path: args.path,\n };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, (args) => {\n return {\n contents: cssLookup.get(args.path),\n loader: 'css',\n resolveDir: basename(args.path),\n };\n });\n\n build.onLoad({ filter: /\\.(js|jsx|ts|tsx)$/ }, async (args) => {\n const rawCode = readFileSync(args.path, 'utf8');\n const { ext, name: filename } = parse(args.path);\n const loader = ext.replace(/^\\./, '') as Loader;\n\n if (nodeModulesRegex.test(args.path)) {\n return {\n loader,\n contents: rawCode,\n };\n }\n\n if (!options) {\n options = {};\n if ('jsxFactory' in build.initialOptions) {\n options.jsxFactory = build.initialOptions.jsxFactory;\n }\n if ('jsxFragment' in build.initialOptions) {\n options.jsxFragment = build.initialOptions.jsxFragment;\n }\n }\n\n const transformed = transformSync(rawCode, {\n ...options,\n sourcefile: args.path,\n sourcemap: sourceMap,\n loader,\n });\n let { code } = transformed;\n\n if (sourceMap) {\n const esbuildMap = Buffer.from(transformed.map).toString('base64');\n code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;\n }\n\n const transformServices = {\n options: {\n filename: args.path,\n root: process.cwd(),\n preprocessor,\n pluginOptions: rest,\n },\n cache,\n };\n\n const result = await transform(transformServices, code, asyncResolve);\n\n if (!result.cssText) {\n return {\n contents: code,\n loader,\n resolveDir: dirname(args.path),\n };\n }\n\n let { cssText } = result;\n\n const slug = slugify(cssText);\n const cssFilename = `${filename}_${slug}.wyw.css`;\n\n let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;\n\n if (sourceMap && result.cssSourceMapText) {\n const map = Buffer.from(result.cssSourceMapText).toString('base64');\n cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;\n const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;\n }\n\n cssLookup.set(cssFilename, cssText);\n\n return {\n contents,\n loader,\n resolveDir: dirname(args.path),\n };\n });\n },\n };\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;;AAEA,SAASA,YAAY,QAAQ,IAAI;AACjC,SAASC,QAAQ,EAAEC,OAAO,EAAEC,UAAU,EAAEC,IAAI,EAAEC,KAAK,EAAEC,KAAK,QAAQ,MAAM;AAGxE,SAASC,aAAa,QAAQ,SAAS;AAGvC,SACEC,OAAO,EACPC,SAAS,EACTC,wBAAwB,QACnB,sBAAsB;AAQ7B,MAAMC,gBAAgB,GAAG,wCAAwC;AAEjE,eAAe,SAASC,OAAOA,CAAC;EAC9BC,SAAS;EACTC,YAAY;EACZC,cAAc;EACd,GAAGC;AACiB,CAAC,GAAG,CAAC,CAAC,EAAU;EACpC,IAAIC,OAAO,GAAGF,cAAc;EAC5B,MAAMG,KAAK,GAAG,IAAIR,wBAAwB,CAAC,CAAC;EAC5C,OAAO;IACLS,IAAI,EAAE,WAAW;IACjBC,KAAKA,CAACC,KAAK,EAAE;MACX,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAiB,CAAC;MAE3C,MAAMC,YAAY,GAAG,MAAAA,CACnBC,KAAa,EACbC,QAAgB,KACI;QACpB,MAAMC,OAAO,GAAGxB,UAAU,CAACuB,QAAQ,CAAC,GAChCxB,OAAO,CAACwB,QAAQ,CAAC,GACjBtB,IAAI,CAACwB,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE3B,OAAO,CAACwB,QAAQ,CAAC,CAAC;QAE1C,MAAMI,MAAM,GAAG,MAAMT,KAAK,CAACU,OAAO,CAACN,KAAK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AC,GAAGrC,MAAM;QAExB,MAAMsC,IAAI,GAAG5D,OAAO,CAAC2D,OAAO,CAAC;QAC7B,MAAME,WAAW,GAAI,GAAEnB,QAAS,IAAGkB,IAAK,UAAS;QAEjD,IAAIvB,QAAQ,GAAI,UAASyB,IAAI,CAACC,SAAS,CAACF,WAAW,CAAE,KAAIvC,MAAM,CAAC4B,IAAK,EAAC;QAEtE,IAAI7C,SAAS,IAAIiB,MAAM,CAAC0C,gBAAgB,EAAE;UACxC,MAAMV,GAAG,GAAGF,MAAM,CAACC,IAAI,CAAC/B,MAAM,CAAC0C,gBAAgB,CAAC,CAACT,QAAQ,CAAC,QAAQ,CAAC;UACnEI,OAAO,IAAK,qDAAoDL,GAAI,IAAG;UACvE,MAAMW,MAAM,GAAGb,MAAM,CAACC,IAAI,CAACS,IAAI,CAACC,SAAS,CAACzC,MAAM,CAACjB,SAAS,CAAC,CAAC,CAACkD,QAAQ,CACnE,QACF,CAAC;UACDlB,QAAQ,IAAK,qDAAoD4B,MAAO,IAAG;QAC7E;QAEAnD,SAAS,CAACoD,GAAG,CAACL,WAAW,EAAEF,OAAO,CAAC;QAEnC,OAAO;UACLtB,QAAQ;UACRE,MAAM;UACNf,UAAU,EAAE9B,OAAO,CAACwC,IAAI,CAACL,IAAI;QAC/B,CAAC;MACH,CAAC,CAAC;IACJ;EACF,CAAC;AACH"}
|
package/lib/index.js
CHANGED
|
@@ -39,16 +39,16 @@ function wywInJS({
|
|
|
39
39
|
return result.path.replace(/\\/g, _path.posix.sep);
|
|
40
40
|
};
|
|
41
41
|
build.onResolve({
|
|
42
|
-
filter: /\.
|
|
42
|
+
filter: /\.wyw\.css$/
|
|
43
43
|
}, args => {
|
|
44
44
|
return {
|
|
45
|
-
namespace: '
|
|
45
|
+
namespace: 'wyw-in-js',
|
|
46
46
|
path: args.path
|
|
47
47
|
};
|
|
48
48
|
});
|
|
49
49
|
build.onLoad({
|
|
50
50
|
filter: /.*/,
|
|
51
|
-
namespace: '
|
|
51
|
+
namespace: 'wyw-in-js'
|
|
52
52
|
}, args => {
|
|
53
53
|
return {
|
|
54
54
|
contents: cssLookup.get(args.path),
|
|
@@ -114,13 +114,13 @@ function wywInJS({
|
|
|
114
114
|
cssText
|
|
115
115
|
} = result;
|
|
116
116
|
const slug = (0, _transform.slugify)(cssText);
|
|
117
|
-
const cssFilename = `${filename}_${slug}.
|
|
117
|
+
const cssFilename = `${filename}_${slug}.wyw.css`;
|
|
118
118
|
let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
|
|
119
119
|
if (sourceMap && result.cssSourceMapText) {
|
|
120
120
|
const map = Buffer.from(result.cssSourceMapText).toString('base64');
|
|
121
121
|
cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
122
|
-
const
|
|
123
|
-
contents += `/*# sourceMappingURL=data:application/json;base64,${
|
|
122
|
+
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
123
|
+
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
124
124
|
}
|
|
125
125
|
cssLookup.set(cssFilename, cssText);
|
|
126
126
|
return {
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["_fs","require","_path","_esbuild","_transform","nodeModulesRegex","wywInJS","sourceMap","preprocessor","esbuildOptions","rest","options","cache","TransformCacheCollection","name","setup","build","cssLookup","Map","asyncResolve","token","importer","context","isAbsolute","dirname","join","process","cwd","result","resolve","resolveDir","kind","errors","length","Error","path","replace","posix","sep","onResolve","filter","args","namespace","onLoad","contents","get","loader","basename","rawCode","readFileSync","ext","filename","parse","test","initialOptions","jsxFactory","jsxFragment","transformed","transformSync","sourcefile","sourcemap","code","esbuildMap","Buffer","from","map","toString","transformServices","root","pluginOptions","transform","cssText","slug","slugify","cssFilename","JSON","stringify","cssSourceMapText","
|
|
1
|
+
{"version":3,"file":"index.js","names":["_fs","require","_path","_esbuild","_transform","nodeModulesRegex","wywInJS","sourceMap","preprocessor","esbuildOptions","rest","options","cache","TransformCacheCollection","name","setup","build","cssLookup","Map","asyncResolve","token","importer","context","isAbsolute","dirname","join","process","cwd","result","resolve","resolveDir","kind","errors","length","Error","path","replace","posix","sep","onResolve","filter","args","namespace","onLoad","contents","get","loader","basename","rawCode","readFileSync","ext","filename","parse","test","initialOptions","jsxFactory","jsxFragment","transformed","transformSync","sourcefile","sourcemap","code","esbuildMap","Buffer","from","map","toString","transformServices","root","pluginOptions","transform","cssText","slug","slugify","cssFilename","JSON","stringify","cssSourceMapText","wywMap","set"],"sources":["../src/index.ts"],"sourcesContent":["/**\n * This file contains an esbuild loader for wyw-in-js.\n * It uses the transform.ts function to generate class names from source code,\n * returns transformed code without template literals and attaches generated source maps\n */\n\nimport { readFileSync } from 'fs';\nimport { basename, dirname, isAbsolute, join, parse, posix } from 'path';\n\nimport type { Plugin, TransformOptions, Loader } from 'esbuild';\nimport { transformSync } from 'esbuild';\n\nimport type { PluginOptions, Preprocessor } from '@wyw-in-js/transform';\nimport {\n slugify,\n transform,\n TransformCacheCollection,\n} from '@wyw-in-js/transform';\n\ntype EsbuildPluginOptions = {\n esbuildOptions?: TransformOptions;\n preprocessor?: Preprocessor;\n sourceMap?: boolean;\n} & Partial<PluginOptions>;\n\nconst nodeModulesRegex = /^(?:.*[\\\\/])?node_modules(?:[\\\\/].*)?$/;\n\nexport default function wywInJS({\n sourceMap,\n preprocessor,\n esbuildOptions,\n ...rest\n}: EsbuildPluginOptions = {}): Plugin {\n let options = esbuildOptions;\n const cache = new TransformCacheCollection();\n return {\n name: 'wyw-in-js',\n setup(build) {\n const cssLookup = new Map<string, string>();\n\n const asyncResolve = async (\n token: string,\n importer: string\n ): Promise<string> => {\n const context = isAbsolute(importer)\n ? dirname(importer)\n : join(process.cwd(), dirname(importer));\n\n const result = await build.resolve(token, {\n resolveDir: context,\n kind: 'import-statement',\n });\n\n if (result.errors.length > 0) {\n throw new Error(`Cannot resolve ${token}`);\n }\n\n return result.path.replace(/\\\\/g, posix.sep);\n };\n\n build.onResolve({ filter: /\\.wyw\\.css$/ }, (args) => {\n return {\n namespace: 'wyw-in-js',\n path: args.path,\n };\n });\n\n build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, (args) => {\n return {\n contents: cssLookup.get(args.path),\n loader: 'css',\n resolveDir: basename(args.path),\n };\n });\n\n build.onLoad({ filter: /\\.(js|jsx|ts|tsx)$/ }, async (args) => {\n const rawCode = readFileSync(args.path, 'utf8');\n const { ext, name: filename } = parse(args.path);\n const loader = ext.replace(/^\\./, '') as Loader;\n\n if (nodeModulesRegex.test(args.path)) {\n return {\n loader,\n contents: rawCode,\n };\n }\n\n if (!options) {\n options = {};\n if ('jsxFactory' in build.initialOptions) {\n options.jsxFactory = build.initialOptions.jsxFactory;\n }\n if ('jsxFragment' in build.initialOptions) {\n options.jsxFragment = build.initialOptions.jsxFragment;\n }\n }\n\n const transformed = transformSync(rawCode, {\n ...options,\n sourcefile: args.path,\n sourcemap: sourceMap,\n loader,\n });\n let { code } = transformed;\n\n if (sourceMap) {\n const esbuildMap = Buffer.from(transformed.map).toString('base64');\n code += `/*# sourceMappingURL=data:application/json;base64,${esbuildMap}*/`;\n }\n\n const transformServices = {\n options: {\n filename: args.path,\n root: process.cwd(),\n preprocessor,\n pluginOptions: rest,\n },\n cache,\n };\n\n const result = await transform(transformServices, code, asyncResolve);\n\n if (!result.cssText) {\n return {\n contents: code,\n loader,\n resolveDir: dirname(args.path),\n };\n }\n\n let { cssText } = result;\n\n const slug = slugify(cssText);\n const cssFilename = `${filename}_${slug}.wyw.css`;\n\n let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;\n\n if (sourceMap && result.cssSourceMapText) {\n const map = Buffer.from(result.cssSourceMapText).toString('base64');\n cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;\n const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString(\n 'base64'\n );\n contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;\n }\n\n cssLookup.set(cssFilename, cssText);\n\n return {\n contents,\n loader,\n resolveDir: dirname(args.path),\n };\n });\n },\n };\n}\n"],"mappings":";;;;;;AAMA,IAAAA,GAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAGA,IAAAE,QAAA,GAAAF,OAAA;AAGA,IAAAG,UAAA,GAAAH,OAAA;AAbA;AACA;AACA;AACA;AACA;;AAqBA,MAAMI,gBAAgB,GAAG,wCAAwC;AAElD,SAASC,OAAOA,CAAC;EAC9BC,SAAS;EACTC,YAAY;EACZC,cAAc;EACd,GAAGC;AACiB,CAAC,GAAG,CAAC,CAAC,EAAU;EACpC,IAAIC,OAAO,GAAGF,cAAc;EAC5B,MAAMG,KAAK,GAAG,IAAIC,mCAAwB,CAAC,CAAC;EAC5C,OAAO;IACLC,IAAI,EAAE,WAAW;IACjBC,KAAKA,CAACC,KAAK,EAAE;MACX,MAAMC,SAAS,GAAG,IAAIC,GAAG,CAAiB,CAAC;MAE3C,MAAMC,YAAY,GAAG,MAAAA,CACnBC,KAAa,EACbC,QAAgB,KACI;QACpB,MAAMC,OAAO,GAAG,IAAAC,gBAAU,EAACF,QAAQ,CAAC,GAChC,IAAAG,aAAO,EAACH,QAAQ,CAAC,GACjB,IAAAI,UAAI,EAACC,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE,IAAAH,aAAO,EAACH,QAAQ,CAAC,CAAC;QAE1C,MAAMO,MAAM,GAAG,MAAMZ,KAAK,CAACa,OAAO,CAACT,KAAK,EAAE;UACxCU,UAAU,EAAER,OAAO;UACnBS,IAAI,EAAE;QACR,CAAC,CAAC;QAEF,IAAIH,MAAM,CAACI,MAAM,CAACC,MAAM,GAAG,CAAC,EAAE;UAC5B,MAAM,IAAIC,KAAK,CAAE,kBAAiBd,KAAM,EAAC,CAAC;QAC5C;QAEA,OAAOQ,MAAM,CAACO,IAAI,CAACC,OAAO,CAAC,KAAK,EAAEC,WAAK,CAACC,GAAG,CAAC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C;QAEtE,IAAItD,SAAS,IAAIqB,MAAM,CAACiD,gBAAgB,EAAE;UACxC,MAAMZ,GAAG,GAAGF,MAAM,CAACC,IAAI,CAACpC,MAAM,CAACiD,gBAAgB,CAAC,CAACX,QAAQ,CAAC,QAAQ,CAAC;UACnEK,OAAO,IAAK,qDAAoDN,GAAI,IAAG;UACvE,MAAMa,MAAM,GAAGf,MAAM,CAACC,IAAI,CAACW,IAAI,CAACC,SAAS,CAAChD,MAAM,CAACrB,SAAS,CAAC,CAAC,CAAC2D,QAAQ,CACnE,QACF,CAAC;UACDtB,QAAQ,IAAK,qDAAoDkC,MAAO,IAAG;QAC7E;QAEA7D,SAAS,CAAC8D,GAAG,CAACL,WAAW,EAAEH,OAAO,CAAC;QAEnC,OAAO;UACL3B,QAAQ;UACRE,MAAM;UACNhB,UAAU,EAAE,IAAAN,aAAO,EAACiB,IAAI,CAACN,IAAI;QAC/B,CAAC;MACH,CAAC,CAAC;IACJ;EACF,CAAC;AACH"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wyw-in-js/esbuild",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@wyw-in-js/shared": "0.
|
|
6
|
-
"@wyw-in-js/transform": "0.
|
|
5
|
+
"@wyw-in-js/shared": "0.2.1",
|
|
6
|
+
"@wyw-in-js/transform": "0.2.1"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
9
|
"@types/node": "^16.18.55",
|
|
10
10
|
"esbuild": "^0.15.16",
|
|
11
|
-
"@wyw-in-js/babel-config": "0.
|
|
12
|
-
"@wyw-in-js/eslint-config": "0.
|
|
13
|
-
"@wyw-in-js/jest-preset": "0.
|
|
14
|
-
"@wyw-in-js/ts-config": "0.
|
|
11
|
+
"@wyw-in-js/babel-config": "0.2.1",
|
|
12
|
+
"@wyw-in-js/eslint-config": "0.2.1",
|
|
13
|
+
"@wyw-in-js/jest-preset": "0.2.1",
|
|
14
|
+
"@wyw-in-js/ts-config": "0.2.1"
|
|
15
15
|
},
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=16.0.0"
|
package/types/index.js
CHANGED
|
@@ -30,13 +30,13 @@ function wywInJS({ sourceMap, preprocessor, esbuildOptions, ...rest } = {}) {
|
|
|
30
30
|
}
|
|
31
31
|
return result.path.replace(/\\/g, path_1.posix.sep);
|
|
32
32
|
};
|
|
33
|
-
build.onResolve({ filter: /\.
|
|
33
|
+
build.onResolve({ filter: /\.wyw\.css$/ }, (args) => {
|
|
34
34
|
return {
|
|
35
|
-
namespace: '
|
|
35
|
+
namespace: 'wyw-in-js',
|
|
36
36
|
path: args.path,
|
|
37
37
|
};
|
|
38
38
|
});
|
|
39
|
-
build.onLoad({ filter: /.*/, namespace: '
|
|
39
|
+
build.onLoad({ filter: /.*/, namespace: 'wyw-in-js' }, (args) => {
|
|
40
40
|
return {
|
|
41
41
|
contents: cssLookup.get(args.path),
|
|
42
42
|
loader: 'css',
|
|
@@ -92,13 +92,13 @@ function wywInJS({ sourceMap, preprocessor, esbuildOptions, ...rest } = {}) {
|
|
|
92
92
|
}
|
|
93
93
|
let { cssText } = result;
|
|
94
94
|
const slug = (0, transform_1.slugify)(cssText);
|
|
95
|
-
const cssFilename = `${filename}_${slug}.
|
|
95
|
+
const cssFilename = `${filename}_${slug}.wyw.css`;
|
|
96
96
|
let contents = `import ${JSON.stringify(cssFilename)}; ${result.code}`;
|
|
97
97
|
if (sourceMap && result.cssSourceMapText) {
|
|
98
98
|
const map = Buffer.from(result.cssSourceMapText).toString('base64');
|
|
99
99
|
cssText += `/*# sourceMappingURL=data:application/json;base64,${map}*/`;
|
|
100
|
-
const
|
|
101
|
-
contents += `/*# sourceMappingURL=data:application/json;base64,${
|
|
100
|
+
const wywMap = Buffer.from(JSON.stringify(result.sourceMap)).toString('base64');
|
|
101
|
+
contents += `/*# sourceMappingURL=data:application/json;base64,${wywMap}*/`;
|
|
102
102
|
}
|
|
103
103
|
cssLookup.set(cssFilename, cssText);
|
|
104
104
|
return {
|