-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
62 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@webx-kit/modernjs-plugin": patch | ||
"@webx-kit/rsbuild-plugin": patch | ||
"@webx-kit/core-plugin": patch | ||
--- | ||
|
||
feat: add css hmr for rsbuild |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import path from 'node:path'; | ||
import { Rspack } from '@rsbuild/shared'; | ||
import { ROOT_NAME, STYLE_ROOT_NAME } from '../constants'; | ||
|
||
export const PLUGIN_NAME = 'webx:content-script-shadow-root'; | ||
|
||
const shadowRootLoader = path.resolve( | ||
__dirname, | ||
process.env.NODE_ENV === 'development' ? 'shadow-root-loader-dev.js' : 'shadow-root-loader.js' | ||
); | ||
|
||
export class CSSExtractPatchPlugin { | ||
constructor(readonly resourceRegExp: RegExp) {} | ||
|
||
apply(compiler: Rspack.Compiler) { | ||
new compiler.webpack.NormalModuleReplacementPlugin(this.resourceRegExp, (resolveData) => { | ||
resolveData.request = `${shadowRootLoader}!${resolveData.request}`; | ||
}).apply(compiler); | ||
} | ||
} | ||
|
||
export function patchCSSLoadingCode(code: string): string { | ||
return code | ||
.replace( | ||
/document\.(querySelectorAll|getElementsByTagName)/g, | ||
// if ROOT_NAME is a ShadowRoot, there is no getElementsByTagName method | ||
`(globalThis.${ROOT_NAME}||document).querySelectorAll` | ||
) | ||
.replace(/document\.head/g, `(globalThis.${STYLE_ROOT_NAME}||document.head)`); | ||
} |
File renamed without changes.
6 changes: 3 additions & 3 deletions
6
...ins/content-scripts/shadow-root-loader.ts → ...gin/src/shadow-root/shadow-root-loader.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.