stylex-webpack 0.2.1-beta.0 → 0.2.1-beta.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/dist/index.d.ts +10 -1
- package/dist/index.js +8 -5
- package/dist/next.d.ts +8 -0
- package/dist/next.js +13 -4
- package/dist/stylex-loader.js +2 -1
- package/package.json +2 -1
package/dist/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ interface StyleXLoaderOptions {
|
|
|
7
7
|
nextjsMode: boolean;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
type CSSTransformer = (css: string) => string | Buffer | Promise<string | Buffer>;
|
|
10
11
|
interface StyleXPluginOption {
|
|
11
12
|
stylexOption?: Partial<Options>;
|
|
12
13
|
/**
|
|
@@ -27,6 +28,13 @@ interface StyleXPluginOption {
|
|
|
27
28
|
* @default false
|
|
28
29
|
*/
|
|
29
30
|
nextjsMode?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Enable other CSS transformation
|
|
33
|
+
*
|
|
34
|
+
* Since stylex-webpack only inject CSS after all loaders, you can not use postcss-loader.
|
|
35
|
+
* With this you can incovate `postcss()` here.
|
|
36
|
+
*/
|
|
37
|
+
transformCss?: CSSTransformer;
|
|
30
38
|
}
|
|
31
39
|
type RegisterStyleXRules = (resourcePath: string, stylexRules: Rule[]) => void;
|
|
32
40
|
declare class StyleXPlugin {
|
|
@@ -34,7 +42,8 @@ declare class StyleXPlugin {
|
|
|
34
42
|
stylexRules: Map<string, readonly Rule[]>;
|
|
35
43
|
useCSSLayers: boolean;
|
|
36
44
|
loaderOption: StyleXLoaderOptions;
|
|
37
|
-
|
|
45
|
+
transformCss: CSSTransformer;
|
|
46
|
+
constructor({ stylexImports, useCSSLayers, stylexOption, nextjsMode, transformCss }?: StyleXPluginOption);
|
|
38
47
|
apply(compiler: webpack.Compiler): void;
|
|
39
48
|
}
|
|
40
49
|
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ const getStyleXRules = (stylexRules, useCSSLayers)=>{
|
|
|
30
30
|
const allRules = Array.from(stylexRules.values()).flat();
|
|
31
31
|
return stylexBabelPlugin.processStylexRules(allRules, useCSSLayers);
|
|
32
32
|
};
|
|
33
|
+
const identityTransfrom = (css)=>css;
|
|
33
34
|
class StyleXPlugin {
|
|
34
35
|
apply(compiler) {
|
|
35
36
|
var _compiler_options_optimization_splitChunks;
|
|
@@ -87,10 +88,10 @@ class StyleXPlugin {
|
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
});
|
|
90
|
-
compilation.hooks.processAssets.
|
|
91
|
+
compilation.hooks.processAssets.tapPromise({
|
|
91
92
|
name: PLUGIN_NAME,
|
|
92
93
|
stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
|
|
93
|
-
}, (assets)=>{
|
|
94
|
+
}, async (assets)=>{
|
|
94
95
|
// on previous step, we create a "stylex" chunk to hold all virtual stylex css
|
|
95
96
|
// the chunk contains all css chunks generated by mini-css-extract-plugin
|
|
96
97
|
// TODO-RSPACK: once again, rspack doesn't have this
|
|
@@ -109,7 +110,7 @@ class StyleXPlugin {
|
|
|
109
110
|
if (!stringifiedStylexRule) {
|
|
110
111
|
continue;
|
|
111
112
|
}
|
|
112
|
-
this.stylexRules.set(cssModule.identifier(), JSON.parse(stringifiedStylexRule));
|
|
113
|
+
this.stylexRules.set(cssModule.identifier(), JSON.parse(decodeURIComponent(stringifiedStylexRule)));
|
|
113
114
|
}
|
|
114
115
|
}
|
|
115
116
|
}
|
|
@@ -122,17 +123,18 @@ class StyleXPlugin {
|
|
|
122
123
|
if (stylexCSS == null) {
|
|
123
124
|
return;
|
|
124
125
|
}
|
|
125
|
-
compilation.updateAsset(cssAssetDetails[0], new RawSource(stylexCSS));
|
|
126
|
+
compilation.updateAsset(cssAssetDetails[0], new RawSource(await this.transformCss(stylexCSS)));
|
|
126
127
|
});
|
|
127
128
|
});
|
|
128
129
|
}
|
|
129
130
|
constructor({ stylexImports = [
|
|
130
131
|
'stylex',
|
|
131
132
|
'@stylexjs/stylex'
|
|
132
|
-
], useCSSLayers = false, stylexOption = {}, nextjsMode = false } = {}){
|
|
133
|
+
], useCSSLayers = false, stylexOption = {}, nextjsMode = false, transformCss = identityTransfrom } = {}){
|
|
133
134
|
_define_property(this, "stylexRules", new Map());
|
|
134
135
|
_define_property(this, "useCSSLayers", void 0);
|
|
135
136
|
_define_property(this, "loaderOption", void 0);
|
|
137
|
+
_define_property(this, "transformCss", void 0);
|
|
136
138
|
this.useCSSLayers = useCSSLayers;
|
|
137
139
|
this.loaderOption = {
|
|
138
140
|
stylexImports,
|
|
@@ -147,6 +149,7 @@ class StyleXPlugin {
|
|
|
147
149
|
},
|
|
148
150
|
nextjsMode
|
|
149
151
|
};
|
|
152
|
+
this.transformCss = transformCss;
|
|
150
153
|
}
|
|
151
154
|
}
|
|
152
155
|
_define_property(StyleXPlugin, "stylexLoader", stylexLoaderPath);
|
package/dist/next.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { NextConfig } from 'next/dist/server/config-shared';
|
|
2
2
|
import { Options } from '@stylexjs/babel-plugin';
|
|
3
3
|
|
|
4
|
+
type CSSTransformer = (css: string) => string | Buffer | Promise<string | Buffer>;
|
|
4
5
|
interface StyleXPluginOption {
|
|
5
6
|
stylexOption?: Partial<Options>;
|
|
6
7
|
/**
|
|
@@ -21,6 +22,13 @@ interface StyleXPluginOption {
|
|
|
21
22
|
* @default false
|
|
22
23
|
*/
|
|
23
24
|
nextjsMode?: boolean;
|
|
25
|
+
/**
|
|
26
|
+
* Enable other CSS transformation
|
|
27
|
+
*
|
|
28
|
+
* Since stylex-webpack only inject CSS after all loaders, you can not use postcss-loader.
|
|
29
|
+
* With this you can incovate `postcss()` here.
|
|
30
|
+
*/
|
|
31
|
+
transformCss?: CSSTransformer;
|
|
24
32
|
}
|
|
25
33
|
|
|
26
34
|
declare const withStyleX: (pluginOptions?: StyleXPluginOption) => (nextConfig?: NextConfig) => NextConfig;
|
package/dist/next.js
CHANGED
|
@@ -41,7 +41,7 @@ const getNextMiniCssExtractPlugin = (isDev)=>{
|
|
|
41
41
|
};
|
|
42
42
|
// Adopt from Next.js' getGlobalCssLoader
|
|
43
43
|
// https://github.com/vercel/next.js/blob/d61b0761efae09bd9cb1201ff134ed8950d9deca/packages/next/src/build/webpack/config/blocks/css/loaders/global.ts#L7
|
|
44
|
-
function getStyleXVirtualCssLoader(ctx, MiniCssExtractPlugin) {
|
|
44
|
+
function getStyleXVirtualCssLoader(ctx, MiniCssExtractPlugin, postcss) {
|
|
45
45
|
const loaders = [];
|
|
46
46
|
// Adopt from Next.js' getClientStyleLoader
|
|
47
47
|
// https://github.com/vercel/next.js/blob/56d35ede8ed2ab25fa8e29583d4e81e3e76a0e29/packages/next/src/build/webpack/config/blocks/css/loaders/global.ts#L7
|
|
@@ -59,7 +59,6 @@ function getStyleXVirtualCssLoader(ctx, MiniCssExtractPlugin) {
|
|
|
59
59
|
// We don't actually use postcss-loader or css-loader to run against
|
|
60
60
|
// the stylex css (which doesn't exist yet).
|
|
61
61
|
// We use this loader to run against the virtual dummy css.
|
|
62
|
-
const postcss = ()=>css.lazyPostCSS(ctx.dir, getSupportedBrowsers(ctx.dir, ctx.dev), undefined);
|
|
63
62
|
loaders.push({
|
|
64
63
|
// https://github.com/vercel/next.js/blob/0572e218afe130656be53f7367bf18c4ea389f7d/packages/next/build/webpack/config/blocks/css/loaders/global.ts#L29-L38
|
|
65
64
|
loader: require.resolve('next/dist/build/webpack/loaders/css-loader/src'),
|
|
@@ -84,13 +83,18 @@ const withStyleX = (pluginOptions)=>(nextConfig = {})=>{
|
|
|
84
83
|
}
|
|
85
84
|
(_config_optimization = config.optimization).splitChunks || (_config_optimization.splitChunks = {});
|
|
86
85
|
(_config_optimization_splitChunks = config.optimization.splitChunks).cacheGroups || (_config_optimization_splitChunks.cacheGroups = {});
|
|
86
|
+
let lazyPostCSSPromise = null;
|
|
87
|
+
const postcss = ()=>{
|
|
88
|
+
lazyPostCSSPromise || (lazyPostCSSPromise = css.lazyPostCSS(ctx.dir, getSupportedBrowsers(ctx.dir, ctx.dev), undefined));
|
|
89
|
+
return lazyPostCSSPromise;
|
|
90
|
+
};
|
|
87
91
|
const MiniCssExtractPlugin = getNextMiniCssExtractPlugin(ctx.dev);
|
|
88
92
|
// Based on https://github.com/vercel/next.js/blob/88a5f263f11cb55907f0d89a4cd53647ee8e96ac/packages/next/build/webpack/config/helpers.ts#L12-L18
|
|
89
93
|
const cssRules = config.module.rules.find((rule)=>Array.isArray(rule.oneOf) && rule.oneOf.some(({ test })=>typeof test === 'object' && typeof test.test === 'function' && test.test('filename.css'))).oneOf;
|
|
90
94
|
// Here we matches virtual css file emitted by StyleXPlugin
|
|
91
95
|
cssRules.unshift({
|
|
92
96
|
test: VIRTUAL_CSS_PATTERN,
|
|
93
|
-
use: getStyleXVirtualCssLoader(ctx, MiniCssExtractPlugin)
|
|
97
|
+
use: getStyleXVirtualCssLoader(ctx, MiniCssExtractPlugin, postcss)
|
|
94
98
|
});
|
|
95
99
|
// StyleX need to emit the css file on both server and client, both during the
|
|
96
100
|
// development and production.
|
|
@@ -134,7 +138,12 @@ const withStyleX = (pluginOptions)=>(nextConfig = {})=>{
|
|
|
134
138
|
dev: ctx.dev
|
|
135
139
|
},
|
|
136
140
|
// Enforce nextjsMode to true
|
|
137
|
-
nextjsMode: true
|
|
141
|
+
nextjsMode: true,
|
|
142
|
+
async transformCss (css) {
|
|
143
|
+
const { postcssWithPlugins } = await postcss();
|
|
144
|
+
const result = await postcssWithPlugins.process(css);
|
|
145
|
+
return result.css;
|
|
146
|
+
}
|
|
138
147
|
}));
|
|
139
148
|
return config;
|
|
140
149
|
}
|
package/dist/stylex-loader.js
CHANGED
|
@@ -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
|
+
// color: #fff is not url safe
|
|
58
|
+
const serializedStyleXRules = encodeURIComponent(JSON.stringify(metadata.stylex));
|
|
58
59
|
if (!nextjsMode) {
|
|
59
60
|
// Normal webpack mode
|
|
60
61
|
// We generate a virtual css file that looks like it is relative to the source
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylex-webpack",
|
|
3
|
-
"version": "0.2.1-beta.
|
|
3
|
+
"version": "0.2.1-beta.2",
|
|
4
4
|
"description": "The another Webpack Plugin for Facebook's StyleX",
|
|
5
5
|
"homepage": "https://github.com/SukkaW/style9-webpack#readme",
|
|
6
6
|
"repository": {
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"mocha": "^10.3.0",
|
|
67
67
|
"mocha-chai-jest-snapshot": "^1.1.4",
|
|
68
68
|
"next": "^14.1.0",
|
|
69
|
+
"postcss": "^8.4.35",
|
|
69
70
|
"rimraf": "^5.0.5",
|
|
70
71
|
"rollup": "^4.10.0",
|
|
71
72
|
"rollup-plugin-copy": "^3.5.0",
|