stylex-webpack 0.4.1 → 0.4.3
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.d.ts +8 -1
- package/dist/index.js +12 -14
- package/dist/next.js +2 -2
- package/dist/stylex-loader.js +3 -2
- package/package.json +17 -14
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ interface StyleXLoaderOptions {
|
|
|
6
6
|
stylexImports: string[];
|
|
7
7
|
stylexOption: Partial<Options>;
|
|
8
8
|
nextjsMode: boolean;
|
|
9
|
+
nextjsAppRouterMode: boolean;
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
type CSSTransformer = (css: string) => string | Buffer | Promise<string | Buffer>;
|
|
@@ -34,6 +35,12 @@ interface StyleXPluginOption {
|
|
|
34
35
|
* @default false
|
|
35
36
|
*/
|
|
36
37
|
nextjsMode?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Next.js App Router Mode
|
|
40
|
+
*
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
nextjsAppRouterMode?: boolean;
|
|
37
44
|
/**
|
|
38
45
|
* Enable other CSS transformation
|
|
39
46
|
*
|
|
@@ -49,7 +56,7 @@ declare class StyleXPlugin {
|
|
|
49
56
|
loaderOption: StyleXLoaderOptions;
|
|
50
57
|
transformCss: CSSTransformer;
|
|
51
58
|
private readonly _virtualModuleInstance;
|
|
52
|
-
constructor({ stylexImports, useCSSLayers, stylexOption, nextjsMode, transformCss }?: StyleXPluginOption);
|
|
59
|
+
constructor({ stylexImports, useCSSLayers, stylexOption, nextjsMode, nextjsAppRouterMode, transformCss }?: StyleXPluginOption);
|
|
53
60
|
apply(compiler: webpack.Compiler): void;
|
|
54
61
|
}
|
|
55
62
|
|
package/dist/index.js
CHANGED
|
@@ -6,7 +6,7 @@ var process = require('node:process');
|
|
|
6
6
|
var VirtualModulesPlugin = require('webpack-virtual-modules');
|
|
7
7
|
var identity = require('foxts/identity');
|
|
8
8
|
|
|
9
|
-
var version = "0.4.
|
|
9
|
+
var version = "0.4.3";
|
|
10
10
|
|
|
11
11
|
const PLUGIN_NAME = 'stylex';
|
|
12
12
|
const VIRTUAL_ENTRYPOINT_CSS_PATH = require.resolve('./stylex.css');
|
|
@@ -150,6 +150,13 @@ class StyleXPlugin {
|
|
|
150
150
|
}
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
|
+
// Let's find the css file that belongs to the fuck-next.js chunk to remove it
|
|
154
|
+
const fuckNextjsChunkCssAssetNames = Object.keys(assets).filter((assetName)=>fuckNextjsChunk.files.has(assetName) && assetName.endsWith('.css'));
|
|
155
|
+
if (fuckNextjsChunkCssAssetNames.length > 0) {
|
|
156
|
+
for (const assetName of fuckNextjsChunkCssAssetNames){
|
|
157
|
+
compilation.deleteAsset(assetName);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
162
|
const stylexCSS = getStyleXRules(this.stylexRules, this.useCSSLayers);
|
|
@@ -157,7 +164,7 @@ class StyleXPlugin {
|
|
|
157
164
|
return;
|
|
158
165
|
}
|
|
159
166
|
const finalCss = await this.transformCss(stylexCSS);
|
|
160
|
-
if (compiler.options.mode === 'development') {
|
|
167
|
+
if (compiler.options.mode === 'development' && this.loaderOption.nextjsAppRouterMode) {
|
|
161
168
|
// In development mode, a.k.a. HMR
|
|
162
169
|
/**
|
|
163
170
|
* Now we write final CSS to virtual module, which acts like `stylex-webpack/stylex.css` has been
|
|
@@ -165,12 +172,6 @@ class StyleXPlugin {
|
|
|
165
172
|
*/ this._virtualModuleInstance.writeModule(VIRTUAL_ENTRYPOINT_CSS_PATH, finalCss.toString());
|
|
166
173
|
} else {
|
|
167
174
|
const stylexChunk = compilation.namedChunks.get(STYLEX_CHUNK_NAME);
|
|
168
|
-
console.log({
|
|
169
|
-
rulesFrom: Array.from(this.stylexRules.keys()),
|
|
170
|
-
mode: compiler.options.mode,
|
|
171
|
-
stylexChunk,
|
|
172
|
-
asssets: Object.keys(assets)
|
|
173
|
-
});
|
|
174
175
|
if (!stylexChunk) return;
|
|
175
176
|
// Let's find the css file that belongs to the stylex chunk
|
|
176
177
|
const stylexChunkCssAssetNames = Object.keys(assets).filter((assetName)=>stylexChunk.files.has(assetName) && assetName.endsWith('.css'));
|
|
@@ -181,10 +182,6 @@ class StyleXPlugin {
|
|
|
181
182
|
console.warn('[stylex-webpack] Multiple CSS assets found for the stylex chunk. This should not happen. Please report this issue.');
|
|
182
183
|
}
|
|
183
184
|
const stylexAssetName = stylexChunkCssAssetNames[0];
|
|
184
|
-
console.log({
|
|
185
|
-
finalCss,
|
|
186
|
-
stylexAssetName
|
|
187
|
-
});
|
|
188
185
|
compilation.updateAsset(stylexAssetName, ()=>new RawSource(finalCss), {
|
|
189
186
|
minimized: false
|
|
190
187
|
});
|
|
@@ -195,7 +192,7 @@ class StyleXPlugin {
|
|
|
195
192
|
constructor({ stylexImports = [
|
|
196
193
|
'stylex',
|
|
197
194
|
'@stylexjs/stylex'
|
|
198
|
-
], useCSSLayers = false, stylexOption = {}, nextjsMode = false, transformCss = identity.identity } = {}){
|
|
195
|
+
], useCSSLayers = false, stylexOption = {}, nextjsMode = false, nextjsAppRouterMode = false, transformCss = identity.identity } = {}){
|
|
199
196
|
_define_property(this, "stylexRules", new Map());
|
|
200
197
|
_define_property(this, "useCSSLayers", void 0);
|
|
201
198
|
_define_property(this, "loaderOption", void 0);
|
|
@@ -213,7 +210,8 @@ class StyleXPlugin {
|
|
|
213
210
|
importSources: stylexImports,
|
|
214
211
|
...stylexOption
|
|
215
212
|
},
|
|
216
|
-
nextjsMode
|
|
213
|
+
nextjsMode,
|
|
214
|
+
nextjsAppRouterMode
|
|
217
215
|
};
|
|
218
216
|
this.transformCss = transformCss;
|
|
219
217
|
}
|
package/dist/next.js
CHANGED
|
@@ -138,13 +138,13 @@ function withStyleX(pluginOptions) {
|
|
|
138
138
|
}));
|
|
139
139
|
}
|
|
140
140
|
config.plugins.push(new index.StyleXPlugin({
|
|
141
|
+
nextjsMode: true,
|
|
142
|
+
nextjsAppRouterMode: true,
|
|
141
143
|
...pluginOptions,
|
|
142
144
|
stylexOption: {
|
|
143
145
|
...pluginOptions?.stylexOption,
|
|
144
146
|
dev: ctx.dev
|
|
145
147
|
},
|
|
146
|
-
// Enforce nextjsMode to true
|
|
147
|
-
nextjsMode: true,
|
|
148
148
|
async transformCss (css) {
|
|
149
149
|
const { postcssWithPlugins } = await postcss();
|
|
150
150
|
const result = await postcssWithPlugins.process(css);
|
package/dist/stylex-loader.js
CHANGED
|
@@ -17,7 +17,7 @@ function stringifyRequest(loaderContext, request) {
|
|
|
17
17
|
const PLUGIN_NAME = 'stylex';
|
|
18
18
|
async function stylexLoader(inputCode, inputSourceMap) {
|
|
19
19
|
const callback = this.async();
|
|
20
|
-
const { stylexImports, stylexOption, nextjsMode } = this.getOptions();
|
|
20
|
+
const { stylexImports, stylexOption, nextjsMode, nextjsAppRouterMode } = this.getOptions();
|
|
21
21
|
// bail out early if the input doesn't contain stylex imports
|
|
22
22
|
if (!stylexImports.some((importName)=>inputCode.includes(importName))) {
|
|
23
23
|
return callback(null, inputCode, inputSourceMap);
|
|
@@ -54,7 +54,8 @@ async function stylexLoader(inputCode, inputSourceMap) {
|
|
|
54
54
|
// TODO-RSPACK: doesn't support custom loader context
|
|
55
55
|
// Find a better way to register stylex rules to the compiler instance
|
|
56
56
|
this.StyleXWebpackContextKey.registerStyleXRules(this.resourcePath, metadata.stylex);
|
|
57
|
-
|
|
57
|
+
// Next.js Pages Router doesn't need CSS import in every page.
|
|
58
|
+
if (nextjsMode && nextjsAppRouterMode) {
|
|
58
59
|
// Next.js App Router doesn't support inline matchResource and inline loaders
|
|
59
60
|
// So we adapt Next.js' "external" css import approach instead
|
|
60
61
|
const urlParams = new URLSearchParams({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylex-webpack",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.3",
|
|
4
4
|
"description": "The another Webpack Plugin for Facebook's StyleX",
|
|
5
5
|
"homepage": "https://github.com/SukkaW/style9-webpack#readme",
|
|
6
6
|
"repository": {
|
|
@@ -49,39 +49,39 @@
|
|
|
49
49
|
"author": "Sukka <https://skk.moe>",
|
|
50
50
|
"license": "MIT",
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@babel/core": "^7.28.
|
|
52
|
+
"@babel/core": "^7.28.4",
|
|
53
53
|
"@babel/plugin-syntax-jsx": "^7.27.1",
|
|
54
54
|
"@babel/plugin-syntax-typescript": "^7.27.1",
|
|
55
55
|
"@types/webpack": "^5.28.5",
|
|
56
|
-
"foxts": "^3.
|
|
56
|
+
"foxts": "^3.13.0",
|
|
57
57
|
"loader-utils": "^3.3.1",
|
|
58
58
|
"ts-dedent": "^2.2.0",
|
|
59
59
|
"webpack-virtual-modules": "^0.6.2"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
|
-
"@eslint-sukka/node": "^
|
|
62
|
+
"@eslint-sukka/node": "^7.0.2",
|
|
63
63
|
"@rollup/plugin-json": "^6.1.0",
|
|
64
64
|
"@swc-node/register": "^1.11.1",
|
|
65
65
|
"@swc/core": "^1.13.5",
|
|
66
66
|
"@types/babel__core": "^7.20.5",
|
|
67
67
|
"@types/loader-utils": "^3.0.0",
|
|
68
68
|
"@types/mocha": "^10.0.10",
|
|
69
|
-
"@types/node": "^22.18.
|
|
70
|
-
"browserslist": "^4.
|
|
69
|
+
"@types/node": "^22.18.3",
|
|
70
|
+
"browserslist": "^4.26.0",
|
|
71
71
|
"bumpp": "^10.2.3",
|
|
72
72
|
"css-loader": "^7.1.2",
|
|
73
|
-
"eslint": "^9.
|
|
74
|
-
"eslint-config-sukka": "^
|
|
75
|
-
"eslint-formatter-sukka": "^
|
|
73
|
+
"eslint": "^9.35.0",
|
|
74
|
+
"eslint-config-sukka": "^7.0.2",
|
|
75
|
+
"eslint-formatter-sukka": "^7.0.2",
|
|
76
76
|
"expect": "^30.1.2",
|
|
77
|
-
"memfs": "^4.
|
|
77
|
+
"memfs": "^4.39.0",
|
|
78
78
|
"mini-css-extract-plugin": "^2.9.4",
|
|
79
79
|
"mocha": "^11.7.2",
|
|
80
80
|
"mocha-expect-snapshot": "^8.0.0",
|
|
81
|
-
"next": "^15.5.
|
|
81
|
+
"next": "^15.5.3",
|
|
82
82
|
"postcss": "^8.5.6",
|
|
83
83
|
"rimraf": "^6.0.1",
|
|
84
|
-
"rollup": "^4.50.
|
|
84
|
+
"rollup": "^4.50.1",
|
|
85
85
|
"rollup-plugin-copy": "^3.5.0",
|
|
86
86
|
"rollup-plugin-dts": "^6.2.3",
|
|
87
87
|
"rollup-plugin-swc3": "^0.12.1",
|
|
@@ -92,10 +92,13 @@
|
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"@stylexjs/babel-plugin": "*"
|
|
94
94
|
},
|
|
95
|
-
"packageManager": "pnpm@10.
|
|
95
|
+
"packageManager": "pnpm@10.16.0",
|
|
96
96
|
"pnpm": {
|
|
97
97
|
"overrides": {
|
|
98
98
|
"eslint>chalk": "npm:picocolors@^1.1.1"
|
|
99
|
-
}
|
|
99
|
+
},
|
|
100
|
+
"onlyBuiltDependencies": [
|
|
101
|
+
"oxc-resolver"
|
|
102
|
+
]
|
|
100
103
|
}
|
|
101
104
|
}
|