@gjsify/rolldown-plugin-gjsify 0.16.0 → 0.16.2
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/lib/plugins/css-as-string.js +56 -5
- package/package.json +12 -11
|
@@ -123,6 +123,19 @@ async function loadNpmBundler() {
|
|
|
123
123
|
// `exports` maps in the target package.json are honored (e.g.
|
|
124
124
|
// `@pixelrpg/gjs` exposes `./index.css` via its exports field — that
|
|
125
125
|
// must resolve through `package.json#exports`, not a direct file probe).
|
|
126
|
+
// A `url()`/asset reference (a `@font-face { src: url('x.woff2') }`, a
|
|
127
|
+
// `background: url('img.png')`, a `data:`/`http:` URL) is NOT a bundle-able
|
|
128
|
+
// CSS module — it is served by the consumer at runtime. lightningcss keeps
|
|
129
|
+
// `url()` verbatim by default, but a bare-specifier asset reference routed
|
|
130
|
+
// through the resolver (a future lightningcss version, or the native Rust
|
|
131
|
+
// `Bundler`) would otherwise hit `req.resolve()` and throw `Cannot find
|
|
132
|
+
// module`, aborting the ENTIRE CSS build over a font/image the bundler was
|
|
133
|
+
// never meant to resolve. This predicate lets the resolver leave such
|
|
134
|
+
// references as-authored so the fonts still load at runtime.
|
|
135
|
+
const ASSET_REF_RE = /\.(woff2?|ttf|otf|eot|svg|png|jpe?g|gif|webp|avif|ico)(\?|#|$)/i;
|
|
136
|
+
function isAssetReference(specifier) {
|
|
137
|
+
return /^(data|https?|file):/i.test(specifier) || ASSET_REF_RE.test(specifier);
|
|
138
|
+
}
|
|
126
139
|
const cssBundleResolver = {
|
|
127
140
|
resolve(specifier, from) {
|
|
128
141
|
if (isAbsolute(specifier))
|
|
@@ -134,7 +147,19 @@ const cssBundleResolver = {
|
|
|
134
147
|
// `createRequire` takes a file URL or path; passing the importer
|
|
135
148
|
// lets it scope its node_modules walk to the right starting point.
|
|
136
149
|
const req = createRequire(pathToFileURL(from).href);
|
|
137
|
-
|
|
150
|
+
try {
|
|
151
|
+
return req.resolve(specifier);
|
|
152
|
+
}
|
|
153
|
+
catch (err) {
|
|
154
|
+
// Not an installed module. If it's a `url()`/asset reference,
|
|
155
|
+
// leave it verbatim so lightningcss keeps the `@font-face` /
|
|
156
|
+
// `url()` rule intact (the consumer serves the asset) instead of
|
|
157
|
+
// crashing the build. A genuine unresolvable CSS `@import`
|
|
158
|
+
// re-throws so the missing dependency still surfaces clearly.
|
|
159
|
+
if (isAssetReference(specifier))
|
|
160
|
+
return specifier;
|
|
161
|
+
throw err;
|
|
162
|
+
}
|
|
138
163
|
},
|
|
139
164
|
};
|
|
140
165
|
function targetsToBrowserslist(targets) {
|
|
@@ -158,11 +183,20 @@ export function cssAsStringPlugin(options = {}) {
|
|
|
158
183
|
return {
|
|
159
184
|
name: 'gjsify-css-as-string',
|
|
160
185
|
load: {
|
|
161
|
-
|
|
186
|
+
// Also match `.scss`/`.sass` — a Sass entry is compiled to flat CSS
|
|
187
|
+
// first (Sass already resolves its own `@use`/`@import`/partials and
|
|
188
|
+
// flattens nesting, so no further lightningcss lowering is needed).
|
|
189
|
+
filter: { id: /\.(css|s[ac]ss)$/ },
|
|
162
190
|
async handler(id) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
191
|
+
let code;
|
|
192
|
+
if (/\.s[ac]ss$/.test(id)) {
|
|
193
|
+
code = await compileSass(id);
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
code = bundle
|
|
197
|
+
? new TextDecoder('utf-8').decode(await loadAndBundleCss(id, targets))
|
|
198
|
+
: await readFile(id, 'utf8');
|
|
199
|
+
}
|
|
166
200
|
return {
|
|
167
201
|
code: `export default ${JSON.stringify(code)};`,
|
|
168
202
|
moduleType: 'js',
|
|
@@ -171,6 +205,23 @@ export function cssAsStringPlugin(options = {}) {
|
|
|
171
205
|
},
|
|
172
206
|
};
|
|
173
207
|
}
|
|
208
|
+
let _sassPromise = null;
|
|
209
|
+
async function compileSass(filename) {
|
|
210
|
+
if (!_sassPromise) {
|
|
211
|
+
// Lazy + indirect specifier so `sass` is only resolved when a Sass file
|
|
212
|
+
// is actually imported (mirrors the lazy lightningcss backend). The
|
|
213
|
+
// `dart-sass` JS API is pure JS, so it loads under GJS + Node alike.
|
|
214
|
+
_sassPromise = import(/* @vite-ignore */ 'sass');
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
const sass = await _sassPromise;
|
|
218
|
+
return sass.compile(filename, { style: 'expanded' }).css;
|
|
219
|
+
}
|
|
220
|
+
catch (err) {
|
|
221
|
+
throw new Error(`gjsify css-as-string: failed to compile Sass file ${filename}. ` +
|
|
222
|
+
`Is the \`sass\` package installed? (${err.message})`);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
174
225
|
async function loadAndBundleCss(filename, targets) {
|
|
175
226
|
if (!_bundlerPromise)
|
|
176
227
|
_bundlerPromise = pickBundler();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gjsify/rolldown-plugin-gjsify",
|
|
3
|
-
"version": "0.16.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "Rolldown / Rollup / Vite plugin orchestrator for GJS, Node, and Browser targets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
@@ -55,20 +55,21 @@
|
|
|
55
55
|
],
|
|
56
56
|
"license": "MIT",
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@gjsify/console": "^0.16.
|
|
59
|
-
"@gjsify/resolve-npm": "^0.16.
|
|
60
|
-
"@gjsify/rolldown-plugin-deepkit": "^0.16.
|
|
61
|
-
"@gjsify/rolldown-plugin-pnp": "^0.16.
|
|
62
|
-
"@gjsify/vite-plugin-blueprint": "^0.16.
|
|
58
|
+
"@gjsify/console": "^0.16.2",
|
|
59
|
+
"@gjsify/resolve-npm": "^0.16.2",
|
|
60
|
+
"@gjsify/rolldown-plugin-deepkit": "^0.16.2",
|
|
61
|
+
"@gjsify/rolldown-plugin-pnp": "^0.16.2",
|
|
62
|
+
"@gjsify/vite-plugin-blueprint": "^0.16.2",
|
|
63
63
|
"@rollup/pluginutils": "^5.4.0",
|
|
64
|
-
"acorn": "^8.
|
|
64
|
+
"acorn": "^8.17.0",
|
|
65
65
|
"acorn-walk": "^8.3.5",
|
|
66
66
|
"fast-glob": "^3.3.3",
|
|
67
|
-
"lightningcss": "^1.32.0"
|
|
67
|
+
"lightningcss": "^1.32.0",
|
|
68
|
+
"sass": "^1.101.0"
|
|
68
69
|
},
|
|
69
70
|
"peerDependencies": {
|
|
70
|
-
"@gjsify/lightningcss-native": "^0.16.
|
|
71
|
-
"rolldown": "^1.1.
|
|
71
|
+
"@gjsify/lightningcss-native": "^0.16.2",
|
|
72
|
+
"rolldown": "^1.1.4"
|
|
72
73
|
},
|
|
73
74
|
"peerDependenciesMeta": {
|
|
74
75
|
"@gjsify/lightningcss-native": {
|
|
@@ -80,7 +81,7 @@
|
|
|
80
81
|
},
|
|
81
82
|
"devDependencies": {
|
|
82
83
|
"@types/node": "^25.9.2",
|
|
83
|
-
"rolldown": "^1.1.
|
|
84
|
+
"rolldown": "^1.1.4",
|
|
84
85
|
"typescript": "^6.0.3"
|
|
85
86
|
},
|
|
86
87
|
"gjsify": {
|