stylex-webpack 0.4.0 → 0.4.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.js
CHANGED
|
@@ -4,13 +4,16 @@ var stylexBabelPlugin = require('@stylexjs/babel-plugin');
|
|
|
4
4
|
var path = require('node:path');
|
|
5
5
|
var process = require('node:process');
|
|
6
6
|
var VirtualModulesPlugin = require('webpack-virtual-modules');
|
|
7
|
+
var identity = require('foxts/identity');
|
|
8
|
+
|
|
9
|
+
var version = "0.4.2";
|
|
7
10
|
|
|
8
11
|
const PLUGIN_NAME = 'stylex';
|
|
9
12
|
const VIRTUAL_ENTRYPOINT_CSS_PATH = require.resolve('./stylex.css');
|
|
10
13
|
const VIRTUAL_ENTRYPOINT_CSS_PATTERN = /stylex\.css/;
|
|
11
14
|
const STYLEX_CHUNK_NAME = '_stylex-webpack-generated';
|
|
12
|
-
require.resolve('./stylex.fuck-nextjs.virtual-carrier.
|
|
13
|
-
const FUCK_NEXTJS_VIRTUAL_CARRIER_PATTERN = /stylex\.fuck-nextjs\.virtual-carrier\.
|
|
15
|
+
require.resolve('./stylex.fuck-nextjs.virtual-carrier.css');
|
|
16
|
+
const FUCK_NEXTJS_VIRTUAL_CARRIER_PATTERN = /stylex\.fuck-nextjs\.virtual-carrier\.css/;
|
|
14
17
|
const FUCK_NEXTJS_VIRTUAL_CARRIERCHUNK_NAME = '_stylex-fuck-nextjs-collect-stylex-rules';
|
|
15
18
|
const INCLUDE_REGEXP = /\.[cm]?[jt]sx?$/;
|
|
16
19
|
|
|
@@ -37,7 +40,6 @@ function getStyleXRules(stylexRules, useCSSLayers) {
|
|
|
37
40
|
const allRules = Array.from(stylexRules.values()).flat();
|
|
38
41
|
return stylexBabelPlugin.processStylexRules(allRules, useCSSLayers);
|
|
39
42
|
}
|
|
40
|
-
const identityTransfrom = (css)=>css;
|
|
41
43
|
class StyleXPlugin {
|
|
42
44
|
apply(compiler) {
|
|
43
45
|
var _compiler_options_optimization_splitChunks;
|
|
@@ -61,6 +63,7 @@ class StyleXPlugin {
|
|
|
61
63
|
compiler.options.optimization.splitChunks.cacheGroups[FUCK_NEXTJS_VIRTUAL_CARRIERCHUNK_NAME] = {
|
|
62
64
|
name: FUCK_NEXTJS_VIRTUAL_CARRIERCHUNK_NAME,
|
|
63
65
|
test: FUCK_NEXTJS_VIRTUAL_CARRIER_PATTERN,
|
|
66
|
+
type: 'css/mini-extract',
|
|
64
67
|
chunks: 'all',
|
|
65
68
|
enforce: true
|
|
66
69
|
};
|
|
@@ -80,10 +83,16 @@ class StyleXPlugin {
|
|
|
80
83
|
}
|
|
81
84
|
});
|
|
82
85
|
});
|
|
83
|
-
const { Compilation, NormalModule } = compiler.webpack;
|
|
84
|
-
|
|
86
|
+
const { Compilation, NormalModule, sources } = compiler.webpack;
|
|
87
|
+
const { RawSource } = sources;
|
|
88
|
+
const meta = JSON.stringify({
|
|
89
|
+
name: 'stylex-webpack',
|
|
90
|
+
packageVersion: version,
|
|
91
|
+
opt: this.loaderOption
|
|
92
|
+
});
|
|
85
93
|
// Apply loader to JS modules
|
|
86
94
|
compiler.hooks.make.tap(PLUGIN_NAME, (compilation)=>{
|
|
95
|
+
compilation.hooks.chunkHash.tap(PLUGIN_NAME, (_, hash)=>hash.update(meta));
|
|
87
96
|
NormalModule.getCompilationHooks(compilation).loader.tap(PLUGIN_NAME, (loaderContext, mod)=>{
|
|
88
97
|
const extname = path.extname(mod.matchResource || mod.resource);
|
|
89
98
|
if (this.loaderOption.nextjsMode && FUCK_NEXTJS_VIRTUAL_CARRIER_PATTERN.test(mod.matchResource || mod.resource)) {
|
|
@@ -114,7 +123,7 @@ class StyleXPlugin {
|
|
|
114
123
|
compilation.hooks.processAssets.tapPromise({
|
|
115
124
|
name: PLUGIN_NAME,
|
|
116
125
|
stage: Compilation.PROCESS_ASSETS_STAGE_PRE_PROCESS
|
|
117
|
-
}, async (
|
|
126
|
+
}, async (assets)=>{
|
|
118
127
|
if (this.loaderOption.nextjsMode) {
|
|
119
128
|
// Collect stylex rules from module instead of self maintained map
|
|
120
129
|
// on previous step, we create a "stylex" chunk to hold all virtual stylex css
|
|
@@ -125,7 +134,6 @@ class StyleXPlugin {
|
|
|
125
134
|
const cssModulesInFuckNextjsChunk = compilation.chunkGraph.getChunkModulesIterableBySourceType(fuckNextjsChunk, 'css/mini-extract');
|
|
126
135
|
// we only re-collect stylex rules if we can found css in the stylex chunk
|
|
127
136
|
if (cssModulesInFuckNextjsChunk) {
|
|
128
|
-
this.stylexRules.clear();
|
|
129
137
|
for (const cssModule of cssModulesInFuckNextjsChunk){
|
|
130
138
|
if (!('_identifier' in cssModule) || typeof cssModule._identifier !== 'string') {
|
|
131
139
|
continue;
|
|
@@ -142,6 +150,13 @@ class StyleXPlugin {
|
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
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
|
+
}
|
|
145
160
|
}
|
|
146
161
|
}
|
|
147
162
|
const stylexCSS = getStyleXRules(this.stylexRules, this.useCSSLayers);
|
|
@@ -149,17 +164,35 @@ class StyleXPlugin {
|
|
|
149
164
|
return;
|
|
150
165
|
}
|
|
151
166
|
const finalCss = await this.transformCss(stylexCSS);
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
167
|
+
if (compiler.options.mode === 'development') {
|
|
168
|
+
// In development mode, a.k.a. HMR
|
|
169
|
+
/**
|
|
170
|
+
* Now we write final CSS to virtual module, which acts like `stylex-webpack/stylex.css` has been
|
|
171
|
+
* updated locally on the disk, and Next.js and webpack will have no choice but to update the global css
|
|
172
|
+
*/ this._virtualModuleInstance.writeModule(VIRTUAL_ENTRYPOINT_CSS_PATH, finalCss.toString());
|
|
173
|
+
} else {
|
|
174
|
+
const stylexChunk = compilation.namedChunks.get(STYLEX_CHUNK_NAME);
|
|
175
|
+
if (!stylexChunk) return;
|
|
176
|
+
// Let's find the css file that belongs to the stylex chunk
|
|
177
|
+
const stylexChunkCssAssetNames = Object.keys(assets).filter((assetName)=>stylexChunk.files.has(assetName) && assetName.endsWith('.css'));
|
|
178
|
+
if (stylexChunkCssAssetNames.length === 0) {
|
|
179
|
+
return;
|
|
180
|
+
}
|
|
181
|
+
if (stylexChunkCssAssetNames.length > 1) {
|
|
182
|
+
console.warn('[stylex-webpack] Multiple CSS assets found for the stylex chunk. This should not happen. Please report this issue.');
|
|
183
|
+
}
|
|
184
|
+
const stylexAssetName = stylexChunkCssAssetNames[0];
|
|
185
|
+
compilation.updateAsset(stylexAssetName, ()=>new RawSource(finalCss), {
|
|
186
|
+
minimized: false
|
|
187
|
+
});
|
|
188
|
+
}
|
|
156
189
|
});
|
|
157
190
|
});
|
|
158
191
|
}
|
|
159
192
|
constructor({ stylexImports = [
|
|
160
193
|
'stylex',
|
|
161
194
|
'@stylexjs/stylex'
|
|
162
|
-
], useCSSLayers = false, stylexOption = {}, nextjsMode = false, transformCss =
|
|
195
|
+
], useCSSLayers = false, stylexOption = {}, nextjsMode = false, transformCss = identity.identity } = {}){
|
|
163
196
|
_define_property(this, "stylexRules", new Map());
|
|
164
197
|
_define_property(this, "useCSSLayers", void 0);
|
|
165
198
|
_define_property(this, "loaderOption", void 0);
|
package/dist/next.js
CHANGED
|
@@ -8,7 +8,7 @@ var index = require('./index');
|
|
|
8
8
|
|
|
9
9
|
require.resolve('./stylex.css');
|
|
10
10
|
const VIRTUAL_ENTRYPOINT_CSS_PATTERN = /stylex\.css/;
|
|
11
|
-
require.resolve('./stylex.fuck-nextjs.virtual-carrier.
|
|
11
|
+
require.resolve('./stylex.fuck-nextjs.virtual-carrier.css');
|
|
12
12
|
|
|
13
13
|
/** Next.js' precompilation add "__esModule: true", but doesn't add an actual default exports */ // @ts-expect-error -- Next.js fucks something up
|
|
14
14
|
const NextMiniCssExtractPlugin = nextMiniCssExtractPluginExports.default;
|
|
@@ -17,7 +17,7 @@ function stylexFuckNextjsVirtualCarrierLoader(inputCode, inputSourceMap) {
|
|
|
17
17
|
const hash = loaderUtils.getHashDigest(stylex, 'xxhash64', 'base62', 32);
|
|
18
18
|
const code = tsDedent.dedent`
|
|
19
19
|
/** stylex rules: ${stylex} */
|
|
20
|
-
|
|
20
|
+
.stylex-fuck-nextjs-${hash} {}
|
|
21
21
|
`;
|
|
22
22
|
callback(null, inputCode + '\n' + code);
|
|
23
23
|
} catch (e) {
|
package/dist/stylex-loader.js
CHANGED
|
@@ -4,7 +4,7 @@ var core = require('@babel/core');
|
|
|
4
4
|
var stylexBabelPlugin = require('@stylexjs/babel-plugin');
|
|
5
5
|
|
|
6
6
|
require.resolve('./stylex.css');
|
|
7
|
-
const FUCK_NEXTJS_VIRTUAL_CARRIER_PATH = require.resolve('./stylex.fuck-nextjs.virtual-carrier.
|
|
7
|
+
const FUCK_NEXTJS_VIRTUAL_CARRIER_PATH = require.resolve('./stylex.fuck-nextjs.virtual-carrier.css');
|
|
8
8
|
function isSupplementedLoaderContext(context) {
|
|
9
9
|
// eslint-disable-next-line prefer-object-has-own -- target older
|
|
10
10
|
return Object.prototype.hasOwnProperty.call(context, 'StyleXWebpackContextKey');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stylex-webpack",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.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": {
|
|
@@ -60,6 +60,7 @@
|
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"@eslint-sukka/node": "^6.23.1",
|
|
63
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
63
64
|
"@swc-node/register": "^1.11.1",
|
|
64
65
|
"@swc/core": "^1.13.5",
|
|
65
66
|
"@types/babel__core": "^7.20.5",
|
/package/dist/{stylex.fuck-nextjs.virtual-carrier.js → stylex.fuck-nextjs.virtual-carrier.css}
RENAMED
|
File without changes
|