Skip to content

Commit

Permalink
chore: bump @rspack & some dependencies (#572)
Browse files Browse the repository at this point in the history
* chore: bump @rspack & some dependencies

* add runtime compat

* Change files

* fix lint
  • Loading branch information
layershifter authored Jun 28, 2024
1 parent ec46fa5 commit 82ce7a8
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 234 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore: improve compat with Rspack",
"packageName": "@griffel/webpack-extraction-plugin",
"email": "[email protected]",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
"@nx/web": "17.2.8",
"@nx/webpack": "17.2.8",
"@nx/workspace": "17.2.8",
"@rspack/cli": "0.5.0",
"@rspack/core": "0.5.0",
"@rspack/cli": "0.7.5",
"@rspack/core": "0.7.5",
"@storybook/addon-essentials": "7.6.8",
"@storybook/core-server": "7.6.8",
"@storybook/react-webpack5": "7.6.8",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { GriffelRenderer } from '@griffel/core';
import { defaultCompareMediaQueries } from '@griffel/core';
import { Compilation, NormalModule } from 'webpack';
import type { Chunk, Compiler, Module, sources } from 'webpack';
import type { Compilation, Chunk, Compiler, Module, sources } from 'webpack';

import { getBundlerRuntime } from './getBundlerRuntime';
import { parseCSSRules } from './parseCSSRules';
import { sortCSSRules } from './sortCSSRules';
import { PLUGIN_NAME, GriffelCssLoaderContextKey, type SupplementedLoaderContext } from './constants';
Expand Down Expand Up @@ -118,6 +118,7 @@ export class GriffelCSSExtractionPlugin {

apply(compiler: Compiler): void {
const IS_RSPACK = Object.prototype.hasOwnProperty.call(compiler.webpack, 'rspackVersion');
const { Compilation, NormalModule } = getBundlerRuntime(IS_RSPACK ? 'rspack' : 'webpack');

// WHAT?
// Prevents ".griffel.css" files from being tree shaken by forcing "sideEffects" setting.
Expand Down
17 changes: 17 additions & 0 deletions packages/webpack-extraction-plugin/src/getBundlerRuntime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { Compilation, NormalModule } from 'webpack';

type BundlerRuntime = {
Compilation: typeof Compilation;
NormalModule: typeof NormalModule;
};

let bundlerRuntime: BundlerRuntime | null = null;

export function getBundlerRuntime(type: 'webpack' | 'rspack'): BundlerRuntime {
if (bundlerRuntime === null) {
// eslint-disable-next-line import/no-extraneous-dependencies
bundlerRuntime = type === 'webpack' ? require('webpack') : require('@rspack/core');
}

return bundlerRuntime!;
}
Loading

0 comments on commit 82ce7a8

Please sign in to comment.