unplugin-inline-css-modules 0.1.3 → 0.1.4
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/astro.d.mts +3 -3
- package/dist/astro.d.ts +3 -3
- package/dist/astro.js +6 -4
- package/dist/astro.js.map +1 -1
- package/dist/astro.mjs +6 -4
- package/dist/astro.mjs.map +1 -1
- package/dist/bun.d.mts +2 -2
- package/dist/bun.d.ts +2 -2
- package/dist/bun.js +4 -2
- package/dist/bun.js.map +1 -1
- package/dist/bun.mjs +4 -2
- package/dist/bun.mjs.map +1 -1
- package/dist/esbuild.d.mts +2 -2
- package/dist/esbuild.d.ts +2 -2
- package/dist/esbuild.js +4 -2
- package/dist/esbuild.js.map +1 -1
- package/dist/esbuild.mjs +4 -2
- package/dist/esbuild.mjs.map +1 -1
- package/dist/farm.d.mts +1 -2
- package/dist/farm.d.ts +1 -2
- package/dist/farm.js +4 -2
- package/dist/farm.js.map +1 -1
- package/dist/farm.mjs +4 -2
- package/dist/farm.mjs.map +1 -1
- package/dist/index.d.mts +1 -14
- package/dist/index.d.ts +1 -14
- package/dist/index.js +2 -128
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -115
- package/dist/index.mjs.map +1 -1
- package/dist/next.d.mts +2 -2
- package/dist/next.d.ts +2 -2
- package/dist/next.js +4 -2
- package/dist/next.js.map +1 -1
- package/dist/next.mjs +4 -2
- package/dist/next.mjs.map +1 -1
- package/dist/nuxt.d.mts +2 -2
- package/dist/nuxt.d.ts +2 -2
- package/dist/nuxt.js +4 -2
- package/dist/nuxt.js.map +1 -1
- package/dist/nuxt.mjs +4 -2
- package/dist/nuxt.mjs.map +1 -1
- package/dist/plugin.d.mts +15 -0
- package/dist/plugin.d.ts +15 -0
- package/dist/plugin.js +154 -0
- package/dist/plugin.js.map +1 -0
- package/dist/plugin.mjs +118 -0
- package/dist/plugin.mjs.map +1 -0
- package/dist/rolldown.d.mts +2 -2
- package/dist/rolldown.d.ts +2 -2
- package/dist/rolldown.js +4 -2
- package/dist/rolldown.js.map +1 -1
- package/dist/rolldown.mjs +4 -2
- package/dist/rolldown.mjs.map +1 -1
- package/dist/rollup.d.mts +2 -2
- package/dist/rollup.d.ts +2 -2
- package/dist/rollup.js +4 -2
- package/dist/rollup.js.map +1 -1
- package/dist/rollup.mjs +4 -2
- package/dist/rollup.mjs.map +1 -1
- package/dist/rspack.d.mts +2 -2
- package/dist/rspack.d.ts +2 -2
- package/dist/rspack.js +4 -2
- package/dist/rspack.js.map +1 -1
- package/dist/rspack.mjs +4 -2
- package/dist/rspack.mjs.map +1 -1
- package/dist/vite.d.mts +2 -2
- package/dist/vite.d.ts +2 -2
- package/dist/vite.js +4 -2
- package/dist/vite.js.map +1 -1
- package/dist/vite.mjs +4 -2
- package/dist/vite.mjs.map +1 -1
- package/dist/webpack.d.mts +2 -2
- package/dist/webpack.d.ts +2 -2
- package/dist/webpack.js +4 -2
- package/dist/webpack.js.map +1 -1
- package/dist/webpack.mjs +4 -2
- package/dist/webpack.mjs.map +1 -1
- package/package.json +1 -1
package/dist/farm.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/farm.ts","../src/index.ts"],"sourcesContent":["import { createFarmPlugin } from 'unplugin'\nimport { unpluginFactory } from './
|
|
1
|
+
{"version":3,"sources":["../src/farm.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { createFarmPlugin } from 'unplugin'\nimport { unpluginFactory } from './plugin'\n\nexport default createFarmPlugin(unpluginFactory) as any\nexport { css } from './index'\n","import type { UnpluginFactory } from 'unplugin'\nimport { createUnplugin } from 'unplugin'\nimport { createHash } from 'crypto'\nimport { mkdirSync, writeFileSync, existsSync } from 'fs'\nimport { join } from 'path'\nimport MagicString from 'magic-string'\n\ntype SupportedExtension = 'css' | 'scss' | 'sass' | 'styl' | 'less'\n\nexport type PluginConfig = {\n fileMatch?: RegExp\n tagName?: string\n extension?: SupportedExtension\n inlineImport?: boolean\n moduleStrategy?: 'virtual' | 'filesystem'\n}\n\nconst matchInlineCssModules =\n /(?:const|var|let)\\s*(\\w+)(?:\\s*:.*)?\\s*=\\s*(\\w+)\\s*`([\\s\\S]*?)`/gm\n\nconst virtualModuleId = 'virtual:inline-css-modules'\nconst webpackModuleId = 'inline-css-modules/virtual'\nconst resolvedVirtualModuleId = '\\0' + virtualModuleId\nconst resolvedWebpackModuleId = '\\0inline-css-modules/virtual'\n\nlet cssModules: Record<string, string> = {}\n\nconst getCacheDir = () =>\n join(process.cwd(), 'node_modules', '.cache', 'inline-css-modules')\nconst getCachePath = (hash: string) => join(getCacheDir(), `${hash}.module.css`)\n\nfunction ensureCacheDir() {\n const dir = getCacheDir()\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true })\n }\n}\n\nfunction hashCss(css: string): string {\n return createHash('md5').update(css).digest('hex')\n}\n\nfunction writeToCache(hash: string, css: string): void {\n ensureCacheDir()\n writeFileSync(getCachePath(hash), css)\n}\n\nexport const unpluginFactory: UnpluginFactory<PluginConfig | undefined> = (\n config = {},\n meta\n) => {\n const fileMatch = config.fileMatch ?? /\\.(tsx|jsx|js|vue|svelte)$/\n const tagName = config.tagName ?? 'css'\n const preprocessor = config.extension ?? 'css'\n const useFilesystem = config.moduleStrategy === 'filesystem'\n const moduleId = useFilesystem ? webpackModuleId : virtualModuleId\n const resolvedId = useFilesystem\n ? resolvedWebpackModuleId\n : resolvedVirtualModuleId\n\n return {\n name: 'inline-css-modules',\n enforce: 'pre',\n resolveId(id) {\n if (id === moduleId || id.startsWith(moduleId + '/')) {\n return resolvedId + id.slice(moduleId.length)\n }\n return undefined\n },\n loadInclude(id) {\n return id.startsWith(resolvedId)\n },\n load(id) {\n if (!id.startsWith(resolvedId + '/')) return undefined\n\n const file = id.slice(resolvedId.length + 1).replace(/\\?used$/, '')\n const css = cssModules[file]\n\n if (!css) return undefined\n\n return {\n code: css,\n map: null,\n }\n },\n transform: {\n filter: {\n id: fileMatch,\n },\n handler(src, id) {\n const s = new MagicString(src)\n const imports: string[] = []\n let hasChanges = false\n\n let match: RegExpExecArray | null\n const importRegex =\n /import\\s*{\\s*(?:css|inlineCss)\\s*(?:as\\s*\\w+\\s*)?}\\s*from\\s*('|\"|`)unplugin-inline-css-modules\\1;?/gm\n while ((match = importRegex.exec(src)) !== null) {\n s.remove(match.index, match.index + match[0].length)\n hasChanges = true\n }\n\n matchInlineCssModules.lastIndex = 0\n while ((match = matchInlineCssModules.exec(src)) !== null) {\n const [fullMatch, variableName, tag, css] = match\n if (tag !== tagName) continue\n\n const hash = hashCss(css)\n const filename = `${hash}.module.${preprocessor}`\n cssModules[filename] = css\n\n let importStatement: string\n if (useFilesystem) {\n writeToCache(hash, css)\n importStatement = `import ${variableName} from \"${getCachePath(hash)}\"`\n } else {\n importStatement = `import ${variableName} from \"${moduleId}/${filename}\"`\n }\n\n if (config.inlineImport === false) {\n imports.push(importStatement)\n s.overwrite(match.index, match.index + fullMatch.length, '')\n } else {\n s.overwrite(\n match.index,\n match.index + fullMatch.length,\n importStatement\n )\n }\n hasChanges = true\n }\n\n if (imports.length) {\n s.prepend(imports.join('\\n') + '\\n')\n }\n\n if (!hasChanges) {\n return null\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({ source: id, includeContent: true }),\n }\n },\n },\n }\n}\n\nexport const unplugin = createUnplugin(unpluginFactory)\n\nexport default unplugin\n","export const css = (_: TemplateStringsArray): Record<string, string> => ({})\n"],"mappings":";AAAA,SAAS,wBAAwB;;;ACCjC,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,WAAW,eAAe,kBAAkB;AACrD,SAAS,YAAY;AACrB,OAAO,iBAAiB;AAYxB,IAAM,wBACJ;AAEF,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;AACxB,IAAM,0BAA0B,OAAO;AACvC,IAAM,0BAA0B;AAEhC,IAAI,aAAqC,CAAC;AAE1C,IAAM,cAAc,MAClB,KAAK,QAAQ,IAA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EAAE,QAAQ,IAAI,gBAAgB,KAAK,CAAC;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,WAAW,eAAe,eAAe;;;ACrJ/C,IAAM,MAAM,CAAC,OAAqD,CAAC;;;AFG1E,IAAO,eAAQ,iBAAiB,eAAe;","names":["css"]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import * as unplugin$1 from 'unplugin';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
|
|
4
|
-
type SupportedExtension = 'css' | 'scss' | 'sass' | 'styl' | 'less';
|
|
5
|
-
type PluginConfig = {
|
|
6
|
-
fileMatch?: RegExp;
|
|
7
|
-
tagName?: string;
|
|
8
|
-
extension?: SupportedExtension;
|
|
9
|
-
inlineImport?: boolean;
|
|
10
|
-
moduleStrategy?: 'virtual' | 'filesystem';
|
|
11
|
-
};
|
|
12
1
|
declare const css: (_: TemplateStringsArray) => Record<string, string>;
|
|
13
|
-
declare const unpluginFactory: UnpluginFactory<PluginConfig | undefined>;
|
|
14
|
-
declare const unplugin: unplugin$1.UnpluginInstance<PluginConfig | undefined, boolean>;
|
|
15
2
|
|
|
16
|
-
export {
|
|
3
|
+
export { css };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import * as unplugin$1 from 'unplugin';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
|
|
4
|
-
type SupportedExtension = 'css' | 'scss' | 'sass' | 'styl' | 'less';
|
|
5
|
-
type PluginConfig = {
|
|
6
|
-
fileMatch?: RegExp;
|
|
7
|
-
tagName?: string;
|
|
8
|
-
extension?: SupportedExtension;
|
|
9
|
-
inlineImport?: boolean;
|
|
10
|
-
moduleStrategy?: 'virtual' | 'filesystem';
|
|
11
|
-
};
|
|
12
1
|
declare const css: (_: TemplateStringsArray) => Record<string, string>;
|
|
13
|
-
declare const unpluginFactory: UnpluginFactory<PluginConfig | undefined>;
|
|
14
|
-
declare const unplugin: unplugin$1.UnpluginInstance<PluginConfig | undefined, boolean>;
|
|
15
2
|
|
|
16
|
-
export {
|
|
3
|
+
export { css };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,141 +15,17 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
21
|
var src_exports = {};
|
|
32
22
|
__export(src_exports, {
|
|
33
|
-
css: () => css
|
|
34
|
-
default: () => src_default,
|
|
35
|
-
unplugin: () => unplugin,
|
|
36
|
-
unpluginFactory: () => unpluginFactory
|
|
23
|
+
css: () => css
|
|
37
24
|
});
|
|
38
25
|
module.exports = __toCommonJS(src_exports);
|
|
39
|
-
var import_unplugin = require("unplugin");
|
|
40
|
-
var import_crypto = require("crypto");
|
|
41
|
-
var import_fs = require("fs");
|
|
42
|
-
var import_path = require("path");
|
|
43
|
-
var import_magic_string = __toESM(require("magic-string"));
|
|
44
|
-
var matchInlineCssModules = /(?:const|var|let)\s*(\w+)(?:\s*:.*)?\s*=\s*(\w+)\s*`([\s\S]*?)`/gm;
|
|
45
26
|
var css = (_) => ({});
|
|
46
|
-
var virtualModuleId = "virtual:inline-css-modules";
|
|
47
|
-
var webpackModuleId = "inline-css-modules/virtual";
|
|
48
|
-
var resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
49
|
-
var resolvedWebpackModuleId = "\0inline-css-modules/virtual";
|
|
50
|
-
var cssModules = {};
|
|
51
|
-
var getCacheDir = () => (0, import_path.join)(process.cwd(), "node_modules", ".cache", "inline-css-modules");
|
|
52
|
-
var getCachePath = (hash) => (0, import_path.join)(getCacheDir(), `${hash}.module.css`);
|
|
53
|
-
function ensureCacheDir() {
|
|
54
|
-
const dir = getCacheDir();
|
|
55
|
-
if (!(0, import_fs.existsSync)(dir)) {
|
|
56
|
-
(0, import_fs.mkdirSync)(dir, { recursive: true });
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
function hashCss(css2) {
|
|
60
|
-
return (0, import_crypto.createHash)("md5").update(css2).digest("hex");
|
|
61
|
-
}
|
|
62
|
-
function writeToCache(hash, css2) {
|
|
63
|
-
ensureCacheDir();
|
|
64
|
-
(0, import_fs.writeFileSync)(getCachePath(hash), css2);
|
|
65
|
-
}
|
|
66
|
-
var unpluginFactory = (config = {}, meta) => {
|
|
67
|
-
const fileMatch = config.fileMatch ?? /\.(tsx|jsx|js|vue|svelte)$/;
|
|
68
|
-
const tagName = config.tagName ?? "css";
|
|
69
|
-
const preprocessor = config.extension ?? "css";
|
|
70
|
-
const useFilesystem = config.moduleStrategy === "filesystem";
|
|
71
|
-
const moduleId = useFilesystem ? webpackModuleId : virtualModuleId;
|
|
72
|
-
const resolvedId = useFilesystem ? resolvedWebpackModuleId : resolvedVirtualModuleId;
|
|
73
|
-
return {
|
|
74
|
-
name: "inline-css-modules",
|
|
75
|
-
enforce: "pre",
|
|
76
|
-
resolveId(id) {
|
|
77
|
-
if (id === moduleId || id.startsWith(moduleId + "/")) {
|
|
78
|
-
return resolvedId + id.slice(moduleId.length);
|
|
79
|
-
}
|
|
80
|
-
return void 0;
|
|
81
|
-
},
|
|
82
|
-
loadInclude(id) {
|
|
83
|
-
return id.startsWith(resolvedId);
|
|
84
|
-
},
|
|
85
|
-
load(id) {
|
|
86
|
-
if (!id.startsWith(resolvedId + "/")) return void 0;
|
|
87
|
-
const file = id.slice(resolvedId.length + 1).replace(/\?used$/, "");
|
|
88
|
-
const css2 = cssModules[file];
|
|
89
|
-
if (!css2) return void 0;
|
|
90
|
-
return {
|
|
91
|
-
code: css2,
|
|
92
|
-
map: null
|
|
93
|
-
};
|
|
94
|
-
},
|
|
95
|
-
transform: {
|
|
96
|
-
filter: {
|
|
97
|
-
id: fileMatch
|
|
98
|
-
},
|
|
99
|
-
handler(src, id) {
|
|
100
|
-
const s = new import_magic_string.default(src);
|
|
101
|
-
const imports = [];
|
|
102
|
-
let hasChanges = false;
|
|
103
|
-
let match;
|
|
104
|
-
const importRegex = /import\s*{\s*(?:css|inlineCss)\s*(?:as\s*\w+\s*)?}\s*from\s*('|"|`)unplugin-inline-css-modules\1;?/gm;
|
|
105
|
-
while ((match = importRegex.exec(src)) !== null) {
|
|
106
|
-
s.remove(match.index, match.index + match[0].length);
|
|
107
|
-
hasChanges = true;
|
|
108
|
-
}
|
|
109
|
-
matchInlineCssModules.lastIndex = 0;
|
|
110
|
-
while ((match = matchInlineCssModules.exec(src)) !== null) {
|
|
111
|
-
const [fullMatch, variableName, tag, css2] = match;
|
|
112
|
-
if (tag !== tagName) continue;
|
|
113
|
-
const hash = hashCss(css2);
|
|
114
|
-
const filename = `${hash}.module.${preprocessor}`;
|
|
115
|
-
cssModules[filename] = css2;
|
|
116
|
-
let importStatement;
|
|
117
|
-
if (useFilesystem) {
|
|
118
|
-
writeToCache(hash, css2);
|
|
119
|
-
importStatement = `import ${variableName} from "${getCachePath(hash)}"`;
|
|
120
|
-
} else {
|
|
121
|
-
importStatement = `import ${variableName} from "${moduleId}/${filename}"`;
|
|
122
|
-
}
|
|
123
|
-
if (config.inlineImport === false) {
|
|
124
|
-
imports.push(importStatement);
|
|
125
|
-
s.overwrite(match.index, match.index + fullMatch.length, "");
|
|
126
|
-
} else {
|
|
127
|
-
s.overwrite(
|
|
128
|
-
match.index,
|
|
129
|
-
match.index + fullMatch.length,
|
|
130
|
-
importStatement
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
hasChanges = true;
|
|
134
|
-
}
|
|
135
|
-
if (imports.length) {
|
|
136
|
-
s.prepend(imports.join("\n") + "\n");
|
|
137
|
-
}
|
|
138
|
-
if (!hasChanges) {
|
|
139
|
-
return null;
|
|
140
|
-
}
|
|
141
|
-
return {
|
|
142
|
-
code: s.toString(),
|
|
143
|
-
map: s.generateMap({ source: id, includeContent: true })
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
};
|
|
149
|
-
var unplugin = (0, import_unplugin.createUnplugin)(unpluginFactory);
|
|
150
|
-
var src_default = unplugin;
|
|
151
27
|
// Annotate the CommonJS export names for ESM import in node:
|
|
152
28
|
0 && (module.exports = {
|
|
153
|
-
css
|
|
154
|
-
unplugin,
|
|
155
|
-
unpluginFactory
|
|
29
|
+
css
|
|
156
30
|
});
|
|
157
31
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export const css = (_: TemplateStringsArray): Record<string, string> => ({})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAO,IAAM,MAAM,CAAC,OAAqD,CAAC;","names":[]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,120 +1,6 @@
|
|
|
1
1
|
// src/index.ts
|
|
2
|
-
import { createUnplugin } from "unplugin";
|
|
3
|
-
import { createHash } from "crypto";
|
|
4
|
-
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
|
5
|
-
import { join } from "path";
|
|
6
|
-
import MagicString from "magic-string";
|
|
7
|
-
var matchInlineCssModules = /(?:const|var|let)\s*(\w+)(?:\s*:.*)?\s*=\s*(\w+)\s*`([\s\S]*?)`/gm;
|
|
8
2
|
var css = (_) => ({});
|
|
9
|
-
var virtualModuleId = "virtual:inline-css-modules";
|
|
10
|
-
var webpackModuleId = "inline-css-modules/virtual";
|
|
11
|
-
var resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
12
|
-
var resolvedWebpackModuleId = "\0inline-css-modules/virtual";
|
|
13
|
-
var cssModules = {};
|
|
14
|
-
var getCacheDir = () => join(process.cwd(), "node_modules", ".cache", "inline-css-modules");
|
|
15
|
-
var getCachePath = (hash) => join(getCacheDir(), `${hash}.module.css`);
|
|
16
|
-
function ensureCacheDir() {
|
|
17
|
-
const dir = getCacheDir();
|
|
18
|
-
if (!existsSync(dir)) {
|
|
19
|
-
mkdirSync(dir, { recursive: true });
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function hashCss(css2) {
|
|
23
|
-
return createHash("md5").update(css2).digest("hex");
|
|
24
|
-
}
|
|
25
|
-
function writeToCache(hash, css2) {
|
|
26
|
-
ensureCacheDir();
|
|
27
|
-
writeFileSync(getCachePath(hash), css2);
|
|
28
|
-
}
|
|
29
|
-
var unpluginFactory = (config = {}, meta) => {
|
|
30
|
-
const fileMatch = config.fileMatch ?? /\.(tsx|jsx|js|vue|svelte)$/;
|
|
31
|
-
const tagName = config.tagName ?? "css";
|
|
32
|
-
const preprocessor = config.extension ?? "css";
|
|
33
|
-
const useFilesystem = config.moduleStrategy === "filesystem";
|
|
34
|
-
const moduleId = useFilesystem ? webpackModuleId : virtualModuleId;
|
|
35
|
-
const resolvedId = useFilesystem ? resolvedWebpackModuleId : resolvedVirtualModuleId;
|
|
36
|
-
return {
|
|
37
|
-
name: "inline-css-modules",
|
|
38
|
-
enforce: "pre",
|
|
39
|
-
resolveId(id) {
|
|
40
|
-
if (id === moduleId || id.startsWith(moduleId + "/")) {
|
|
41
|
-
return resolvedId + id.slice(moduleId.length);
|
|
42
|
-
}
|
|
43
|
-
return void 0;
|
|
44
|
-
},
|
|
45
|
-
loadInclude(id) {
|
|
46
|
-
return id.startsWith(resolvedId);
|
|
47
|
-
},
|
|
48
|
-
load(id) {
|
|
49
|
-
if (!id.startsWith(resolvedId + "/")) return void 0;
|
|
50
|
-
const file = id.slice(resolvedId.length + 1).replace(/\?used$/, "");
|
|
51
|
-
const css2 = cssModules[file];
|
|
52
|
-
if (!css2) return void 0;
|
|
53
|
-
return {
|
|
54
|
-
code: css2,
|
|
55
|
-
map: null
|
|
56
|
-
};
|
|
57
|
-
},
|
|
58
|
-
transform: {
|
|
59
|
-
filter: {
|
|
60
|
-
id: fileMatch
|
|
61
|
-
},
|
|
62
|
-
handler(src, id) {
|
|
63
|
-
const s = new MagicString(src);
|
|
64
|
-
const imports = [];
|
|
65
|
-
let hasChanges = false;
|
|
66
|
-
let match;
|
|
67
|
-
const importRegex = /import\s*{\s*(?:css|inlineCss)\s*(?:as\s*\w+\s*)?}\s*from\s*('|"|`)unplugin-inline-css-modules\1;?/gm;
|
|
68
|
-
while ((match = importRegex.exec(src)) !== null) {
|
|
69
|
-
s.remove(match.index, match.index + match[0].length);
|
|
70
|
-
hasChanges = true;
|
|
71
|
-
}
|
|
72
|
-
matchInlineCssModules.lastIndex = 0;
|
|
73
|
-
while ((match = matchInlineCssModules.exec(src)) !== null) {
|
|
74
|
-
const [fullMatch, variableName, tag, css2] = match;
|
|
75
|
-
if (tag !== tagName) continue;
|
|
76
|
-
const hash = hashCss(css2);
|
|
77
|
-
const filename = `${hash}.module.${preprocessor}`;
|
|
78
|
-
cssModules[filename] = css2;
|
|
79
|
-
let importStatement;
|
|
80
|
-
if (useFilesystem) {
|
|
81
|
-
writeToCache(hash, css2);
|
|
82
|
-
importStatement = `import ${variableName} from "${getCachePath(hash)}"`;
|
|
83
|
-
} else {
|
|
84
|
-
importStatement = `import ${variableName} from "${moduleId}/${filename}"`;
|
|
85
|
-
}
|
|
86
|
-
if (config.inlineImport === false) {
|
|
87
|
-
imports.push(importStatement);
|
|
88
|
-
s.overwrite(match.index, match.index + fullMatch.length, "");
|
|
89
|
-
} else {
|
|
90
|
-
s.overwrite(
|
|
91
|
-
match.index,
|
|
92
|
-
match.index + fullMatch.length,
|
|
93
|
-
importStatement
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
hasChanges = true;
|
|
97
|
-
}
|
|
98
|
-
if (imports.length) {
|
|
99
|
-
s.prepend(imports.join("\n") + "\n");
|
|
100
|
-
}
|
|
101
|
-
if (!hasChanges) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
return {
|
|
105
|
-
code: s.toString(),
|
|
106
|
-
map: s.generateMap({ source: id, includeContent: true })
|
|
107
|
-
};
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
};
|
|
111
|
-
};
|
|
112
|
-
var unplugin = createUnplugin(unpluginFactory);
|
|
113
|
-
var src_default = unplugin;
|
|
114
3
|
export {
|
|
115
|
-
css
|
|
116
|
-
src_default as default,
|
|
117
|
-
unplugin,
|
|
118
|
-
unpluginFactory
|
|
4
|
+
css
|
|
119
5
|
};
|
|
120
6
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export const css = (_: TemplateStringsArray): Record<string, string> => ({})\n"],"mappings":";AAAO,IAAM,MAAM,CAAC,OAAqD,CAAC;","names":[]}
|
package/dist/next.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PluginConfig } from './
|
|
1
|
+
import { PluginConfig } from './plugin.mjs';
|
|
2
2
|
export { css } from './index.mjs';
|
|
3
3
|
import 'unplugin';
|
|
4
4
|
|
|
5
5
|
declare function export_default(options?: PluginConfig): WebpackPluginInstance;
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { export_default as default };
|
package/dist/next.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PluginConfig } from './
|
|
1
|
+
import { PluginConfig } from './plugin.js';
|
|
2
2
|
export { css } from './index.js';
|
|
3
3
|
import 'unplugin';
|
|
4
4
|
|
|
5
5
|
declare function export_default(options?: PluginConfig): WebpackPluginInstance;
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { export_default as default };
|
package/dist/next.js
CHANGED
|
@@ -36,14 +36,13 @@ __export(next_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(next_exports);
|
|
37
37
|
var import_unplugin2 = require("unplugin");
|
|
38
38
|
|
|
39
|
-
// src/
|
|
39
|
+
// src/plugin.ts
|
|
40
40
|
var import_unplugin = require("unplugin");
|
|
41
41
|
var import_crypto = require("crypto");
|
|
42
42
|
var import_fs = require("fs");
|
|
43
43
|
var import_path = require("path");
|
|
44
44
|
var import_magic_string = __toESM(require("magic-string"));
|
|
45
45
|
var matchInlineCssModules = /(?:const|var|let)\s*(\w+)(?:\s*:.*)?\s*=\s*(\w+)\s*`([\s\S]*?)`/gm;
|
|
46
|
-
var css = (_) => ({});
|
|
47
46
|
var virtualModuleId = "virtual:inline-css-modules";
|
|
48
47
|
var webpackModuleId = "inline-css-modules/virtual";
|
|
49
48
|
var resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
@@ -149,6 +148,9 @@ var unpluginFactory = (config = {}, meta) => {
|
|
|
149
148
|
};
|
|
150
149
|
var unplugin = (0, import_unplugin.createUnplugin)(unpluginFactory);
|
|
151
150
|
|
|
151
|
+
// src/index.ts
|
|
152
|
+
var css = (_) => ({});
|
|
153
|
+
|
|
152
154
|
// src/next.ts
|
|
153
155
|
function next_default(options = {}) {
|
|
154
156
|
return (0, import_unplugin2.createWebpackPlugin)(unpluginFactory)({
|
package/dist/next.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/next.ts","../src/index.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { PluginConfig, unpluginFactory } from './
|
|
1
|
+
{"version":3,"sources":["../src/next.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { PluginConfig, unpluginFactory } from './plugin'\n\nexport default function (options: PluginConfig = {}) {\n return createWebpackPlugin(unpluginFactory)({\n ...options,\n moduleStrategy: options.moduleStrategy || 'filesystem',\n })\n}\n\nexport { css } from './index'\n","import type { UnpluginFactory } from 'unplugin'\nimport { createUnplugin } from 'unplugin'\nimport { createHash } from 'crypto'\nimport { mkdirSync, writeFileSync, existsSync } from 'fs'\nimport { join } from 'path'\nimport MagicString from 'magic-string'\n\ntype SupportedExtension = 'css' | 'scss' | 'sass' | 'styl' | 'less'\n\nexport type PluginConfig = {\n fileMatch?: RegExp\n tagName?: string\n extension?: SupportedExtension\n inlineImport?: boolean\n moduleStrategy?: 'virtual' | 'filesystem'\n}\n\nconst matchInlineCssModules =\n /(?:const|var|let)\\s*(\\w+)(?:\\s*:.*)?\\s*=\\s*(\\w+)\\s*`([\\s\\S]*?)`/gm\n\nconst virtualModuleId = 'virtual:inline-css-modules'\nconst webpackModuleId = 'inline-css-modules/virtual'\nconst resolvedVirtualModuleId = '\\0' + virtualModuleId\nconst resolvedWebpackModuleId = '\\0inline-css-modules/virtual'\n\nlet cssModules: Record<string, string> = {}\n\nconst getCacheDir = () =>\n join(process.cwd(), 'node_modules', '.cache', 'inline-css-modules')\nconst getCachePath = (hash: string) => join(getCacheDir(), `${hash}.module.css`)\n\nfunction ensureCacheDir() {\n const dir = getCacheDir()\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true })\n }\n}\n\nfunction hashCss(css: string): string {\n return createHash('md5').update(css).digest('hex')\n}\n\nfunction writeToCache(hash: string, css: string): void {\n ensureCacheDir()\n writeFileSync(getCachePath(hash), css)\n}\n\nexport const unpluginFactory: UnpluginFactory<PluginConfig | undefined> = (\n config = {},\n meta\n) => {\n const fileMatch = config.fileMatch ?? /\\.(tsx|jsx|js|vue|svelte)$/\n const tagName = config.tagName ?? 'css'\n const preprocessor = config.extension ?? 'css'\n const useFilesystem = config.moduleStrategy === 'filesystem'\n const moduleId = useFilesystem ? webpackModuleId : virtualModuleId\n const resolvedId = useFilesystem\n ? resolvedWebpackModuleId\n : resolvedVirtualModuleId\n\n return {\n name: 'inline-css-modules',\n enforce: 'pre',\n resolveId(id) {\n if (id === moduleId || id.startsWith(moduleId + '/')) {\n return resolvedId + id.slice(moduleId.length)\n }\n return undefined\n },\n loadInclude(id) {\n return id.startsWith(resolvedId)\n },\n load(id) {\n if (!id.startsWith(resolvedId + '/')) return undefined\n\n const file = id.slice(resolvedId.length + 1).replace(/\\?used$/, '')\n const css = cssModules[file]\n\n if (!css) return undefined\n\n return {\n code: css,\n map: null,\n }\n },\n transform: {\n filter: {\n id: fileMatch,\n },\n handler(src, id) {\n const s = new MagicString(src)\n const imports: string[] = []\n let hasChanges = false\n\n let match: RegExpExecArray | null\n const importRegex =\n /import\\s*{\\s*(?:css|inlineCss)\\s*(?:as\\s*\\w+\\s*)?}\\s*from\\s*('|\"|`)unplugin-inline-css-modules\\1;?/gm\n while ((match = importRegex.exec(src)) !== null) {\n s.remove(match.index, match.index + match[0].length)\n hasChanges = true\n }\n\n matchInlineCssModules.lastIndex = 0\n while ((match = matchInlineCssModules.exec(src)) !== null) {\n const [fullMatch, variableName, tag, css] = match\n if (tag !== tagName) continue\n\n const hash = hashCss(css)\n const filename = `${hash}.module.${preprocessor}`\n cssModules[filename] = css\n\n let importStatement: string\n if (useFilesystem) {\n writeToCache(hash, css)\n importStatement = `import ${variableName} from \"${getCachePath(hash)}\"`\n } else {\n importStatement = `import ${variableName} from \"${moduleId}/${filename}\"`\n }\n\n if (config.inlineImport === false) {\n imports.push(importStatement)\n s.overwrite(match.index, match.index + fullMatch.length, '')\n } else {\n s.overwrite(\n match.index,\n match.index + fullMatch.length,\n importStatement\n )\n }\n hasChanges = true\n }\n\n if (imports.length) {\n s.prepend(imports.join('\\n') + '\\n')\n }\n\n if (!hasChanges) {\n return null\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({ source: id, includeContent: true }),\n }\n },\n },\n }\n}\n\nexport const unplugin = createUnplugin(unpluginFactory)\n\nexport default unplugin\n","export const css = (_: TemplateStringsArray): Record<string, string> => ({})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,mBAAoC;;;ACCpC,sBAA+B;AAC/B,oBAA2B;AAC3B,gBAAqD;AACrD,kBAAqB;AACrB,0BAAwB;AAYxB,IAAM,wBACJ;AAEF,IAAM,kBAAkB;AACxB,IAAM,kBAAkB;AACxB,IAAM,0BAA0B,OAAO;AACvC,IAAM,0BAA0B;AAEhC,IAAI,aAAqC,CAAC;AAE1C,IAAM,cAAc,UAClB,kBAAK,QAAQ,IAAI,GAAG,gBAAgB,UAAU,oBAAoB;AACpE,IAAM,eAAe,CAAC,aAAiB,kBAAK,YAAY,GAAG,GAAG,IAAI,aAAa;AAE/E,SAAS,iBAAiB;AACxB,QAAM,MAAM,YAAY;AACxB,MAAI,KAAC,sBAAW,GAAG,GAAG;AACpB,6BAAU,KAAK,EAAE,WAAW,KAAK,CAAC;AAAA,EACpC;AACF;AAEA,SAAS,QAAQC,MAAqB;AACpC,aAAO,0BAAW,KAAK,EAAE,OAAOA,IAAG,EAAE,OAAO,KAAK;AACnD;AAEA,SAAS,aAAa,M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package/dist/next.mjs
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
// src/next.ts
|
|
2
2
|
import { createWebpackPlugin } from "unplugin";
|
|
3
3
|
|
|
4
|
-
// src/
|
|
4
|
+
// src/plugin.ts
|
|
5
5
|
import { createUnplugin } from "unplugin";
|
|
6
6
|
import { createHash } from "crypto";
|
|
7
7
|
import { mkdirSync, writeFileSync, existsSync } from "fs";
|
|
8
8
|
import { join } from "path";
|
|
9
9
|
import MagicString from "magic-string";
|
|
10
10
|
var matchInlineCssModules = /(?:const|var|let)\s*(\w+)(?:\s*:.*)?\s*=\s*(\w+)\s*`([\s\S]*?)`/gm;
|
|
11
|
-
var css = (_) => ({});
|
|
12
11
|
var virtualModuleId = "virtual:inline-css-modules";
|
|
13
12
|
var webpackModuleId = "inline-css-modules/virtual";
|
|
14
13
|
var resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
@@ -114,6 +113,9 @@ var unpluginFactory = (config = {}, meta) => {
|
|
|
114
113
|
};
|
|
115
114
|
var unplugin = createUnplugin(unpluginFactory);
|
|
116
115
|
|
|
116
|
+
// src/index.ts
|
|
117
|
+
var css = (_) => ({});
|
|
118
|
+
|
|
117
119
|
// src/next.ts
|
|
118
120
|
function next_default(options = {}) {
|
|
119
121
|
return createWebpackPlugin(unpluginFactory)({
|
package/dist/next.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/next.ts","../src/index.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { PluginConfig, unpluginFactory } from './
|
|
1
|
+
{"version":3,"sources":["../src/next.ts","../src/plugin.ts","../src/index.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { PluginConfig, unpluginFactory } from './plugin'\n\nexport default function (options: PluginConfig = {}) {\n return createWebpackPlugin(unpluginFactory)({\n ...options,\n moduleStrategy: options.moduleStrategy || 'filesystem',\n })\n}\n\nexport { css } from './index'\n","import type { UnpluginFactory } from 'unplugin'\nimport { createUnplugin } from 'unplugin'\nimport { createHash } from 'crypto'\nimport { mkdirSync, writeFileSync, existsSync } from 'fs'\nimport { join } from 'path'\nimport MagicString from 'magic-string'\n\ntype SupportedExtension = 'css' | 'scss' | 'sass' | 'styl' | 'less'\n\nexport type PluginConfig = {\n fileMatch?: RegExp\n tagName?: string\n extension?: SupportedExtension\n inlineImport?: boolean\n moduleStrategy?: 'virtual' | 'filesystem'\n}\n\nconst matchInlineCssModules =\n /(?:const|var|let)\\s*(\\w+)(?:\\s*:.*)?\\s*=\\s*(\\w+)\\s*`([\\s\\S]*?)`/gm\n\nconst virtualModuleId = 'virtual:inline-css-modules'\nconst webpackModuleId = 'inline-css-modules/virtual'\nconst resolvedVirtualModuleId = '\\0' + virtualModuleId\nconst resolvedWebpackModuleId = '\\0inline-css-modules/virtual'\n\nlet cssModules: Record<string, string> = {}\n\nconst getCacheDir = () =>\n join(process.cwd(), 'node_modules', '.cache', 'inline-css-modules')\nconst getCachePath = (hash: string) => join(getCacheDir(), `${hash}.module.css`)\n\nfunction ensureCacheDir() {\n const dir = getCacheDir()\n if (!existsSync(dir)) {\n mkdirSync(dir, { recursive: true })\n }\n}\n\nfunction hashCss(css: string): string {\n return createHash('md5').update(css).digest('hex')\n}\n\nfunction writeToCache(hash: string, css: string): void {\n ensureCacheDir()\n writeFileSync(getCachePath(hash), css)\n}\n\nexport const unpluginFactory: UnpluginFactory<PluginConfig | undefined> = (\n config = {},\n meta\n) => {\n const fileMatch = config.fileMatch ?? /\\.(tsx|jsx|js|vue|svelte)$/\n const tagName = config.tagName ?? 'css'\n const preprocessor = config.extension ?? 'css'\n const useFilesystem = config.moduleStrategy === 'filesystem'\n const moduleId = useFilesystem ? webpackModuleId : virtualModuleId\n const resolvedId = useFilesystem\n ? resolvedWebpackModuleId\n : resolvedVirtualModuleId\n\n return {\n name: 'inline-css-modules',\n enforce: 'pre',\n resolveId(id) {\n if (id === moduleId || id.startsWith(moduleId + '/')) {\n return resolvedId + id.slice(moduleId.length)\n }\n return undefined\n },\n loadInclude(id) {\n return id.startsWith(resolvedId)\n },\n load(id) {\n if (!id.startsWith(resolvedId + '/')) return undefined\n\n const file = id.slice(resolvedId.length + 1).replace(/\\?used$/, '')\n const css = cssModules[file]\n\n if (!css) return undefined\n\n return {\n code: css,\n map: null,\n }\n },\n transform: {\n filter: {\n id: fileMatch,\n },\n handler(src, id) {\n const s = new MagicString(src)\n const imports: string[] = []\n let hasChanges = false\n\n let match: RegExpExecArray | null\n const importRegex =\n /import\\s*{\\s*(?:css|inlineCss)\\s*(?:as\\s*\\w+\\s*)?}\\s*from\\s*('|\"|`)unplugin-inline-css-modules\\1;?/gm\n while ((match = importRegex.exec(src)) !== null) {\n s.remove(match.index, match.index + match[0].length)\n hasChanges = true\n }\n\n matchInlineCssModules.lastIndex = 0\n while ((match = matchInlineCssModules.exec(src)) !== null) {\n const [fullMatch, variableName, tag, css] = match\n if (tag !== tagName) continue\n\n const hash = hashCss(css)\n const filename = `${hash}.module.${preprocessor}`\n cssModules[filename] = css\n\n let importStatement: string\n if (useFilesystem) {\n writeToCache(hash, css)\n importStatement = `import ${variableName} from \"${getCachePath(hash)}\"`\n } else {\n importStatement = `import ${variableName} from \"${moduleId}/${filename}\"`\n }\n\n if (config.inlineImport === false) {\n imports.push(importStatement)\n s.overwrite(match.index, match.index + fullMatch.length, '')\n } else {\n s.overwrite(\n match.index,\n match.index + fullMatch.length,\n importStatement\n )\n }\n hasChanges = true\n }\n\n if (imports.length) {\n s.prepend(imports.join('\\n') + '\\n')\n }\n\n if (!hasChanges) {\n return null\n }\n\n return {\n code: s.toString(),\n map: s.generateMap({ source: id, includeContent: true }),\n }\n },\n },\n }\n}\n\nexport const unplugin = createUnplugin(unpluginFactory)\n\nexport default unplugin\n","export const css = (_: TemplateStringsArray): Record<string, string> => ({})\n"],"mappings":";AAAA,SAAS,2BAA2B;;;ACCpC,SAAS,sBAAsB;AAC/B,SAAS,kBAAkB;AAC3B,SAAS,WAA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F;AACA,uBAAa;AAAA,QACf;AAEA,YAAI,QAAQ,QAAQ;AAClB,YAAE,QAAQ,QAAQ,KAAK,IAAI,IAAI,IAAI;AAAA,QACrC;AAEA,YAAI,CAAC,YAAY;AACf,iBAAO;AAAA,QACT;AAEA,eAAO;AAAA,UACL,MAAM,EAAE,SAAS;AAAA,UACjB,KAAK,EAAE,YAAY,EAAE,QAAQ,IAAI,gBAAgB,KAAK,CAAC;AAAA,QACzD;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,WAAW,eAAe,eAAe;;;ACrJ/C,IAAM,MAAM,CAAC,OAAqD,CAAC;;;AFG3D,SAAR,aAAkB,UAAwB,CAAC,GAAG;AACnD,SAAO,oBAAoB,eAAe,EAAE;AAAA,IAC1C,GAAG;AAAA,IACH,gBAAgB,QAAQ,kBAAkB;AAAA,EAC5C,CAAC;AACH;","names":["css"]}
|
package/dist/nuxt.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PluginConfig } from './
|
|
1
|
+
import { PluginConfig } from './plugin.mjs';
|
|
2
2
|
export { css } from './index.mjs';
|
|
3
3
|
import 'unplugin';
|
|
4
4
|
|
|
5
5
|
declare function export_default(options?: PluginConfig): WebpackPluginInstance;
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { export_default as default };
|
package/dist/nuxt.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PluginConfig } from './
|
|
1
|
+
import { PluginConfig } from './plugin.js';
|
|
2
2
|
export { css } from './index.js';
|
|
3
3
|
import 'unplugin';
|
|
4
4
|
|
|
5
5
|
declare function export_default(options?: PluginConfig): WebpackPluginInstance;
|
|
6
6
|
|
|
7
|
-
export {
|
|
7
|
+
export { export_default as default };
|
package/dist/nuxt.js
CHANGED
|
@@ -36,14 +36,13 @@ __export(nuxt_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(nuxt_exports);
|
|
37
37
|
var import_unplugin2 = require("unplugin");
|
|
38
38
|
|
|
39
|
-
// src/
|
|
39
|
+
// src/plugin.ts
|
|
40
40
|
var import_unplugin = require("unplugin");
|
|
41
41
|
var import_crypto = require("crypto");
|
|
42
42
|
var import_fs = require("fs");
|
|
43
43
|
var import_path = require("path");
|
|
44
44
|
var import_magic_string = __toESM(require("magic-string"));
|
|
45
45
|
var matchInlineCssModules = /(?:const|var|let)\s*(\w+)(?:\s*:.*)?\s*=\s*(\w+)\s*`([\s\S]*?)`/gm;
|
|
46
|
-
var css = (_) => ({});
|
|
47
46
|
var virtualModuleId = "virtual:inline-css-modules";
|
|
48
47
|
var webpackModuleId = "inline-css-modules/virtual";
|
|
49
48
|
var resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
@@ -149,6 +148,9 @@ var unpluginFactory = (config = {}, meta) => {
|
|
|
149
148
|
};
|
|
150
149
|
var unplugin = (0, import_unplugin.createUnplugin)(unpluginFactory);
|
|
151
150
|
|
|
151
|
+
// src/index.ts
|
|
152
|
+
var css = (_) => ({});
|
|
153
|
+
|
|
152
154
|
// src/nuxt.ts
|
|
153
155
|
function nuxt_default(options = {}) {
|
|
154
156
|
return (0, import_unplugin2.createWebpackPlugin)(unpluginFactory)(options);
|