Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
SoonIter committed Jan 10, 2025
1 parent 45848b2 commit 51e29b8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 38 deletions.
2 changes: 0 additions & 2 deletions examples/react-component-bundle/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export default defineConfig({
{
format: 'esm',
dts: true,
// syntax: 'es5',
output: {
distPath: {
root: './dist/esm',
Expand All @@ -16,7 +15,6 @@ export default defineConfig({
},
{
format: 'cjs',
syntax: 'es5',
dts: true,
output: {
distPath: {
Expand Down
34 changes: 22 additions & 12 deletions packages/core/src/asset/assetConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,47 @@ import type { EnvironmentConfig, RsbuildPlugin } from '@rsbuild/core';
import type { Format } from '../types';
import { LibAssetExtractPlugin } from './LibAssetExtractPlugin';

const PLUGIN_NAME = 'rsbuild:lib-asset-bundleless';
const PLUGIN_NAME = 'rsbuild:lib-asset';

const RSBUILD_SVGR_PLUGIN_NAME = 'rsbuild:svgr';
const pluginLibAsset = ({ bundle }: { bundle: boolean }): RsbuildPlugin => ({
name: PLUGIN_NAME,
pre: [RSBUILD_SVGR_PLUGIN_NAME],
setup(api) {
api.modifyBundlerChain((config, { CHAIN_ID }) => {
// only support transform the svg asset to mixedImport svgr file
// remove issuer to make every svg asset is transformed
const isUsingSvgr = Boolean(
config.module
.rule(CHAIN_ID.RULE.SVG)
.oneOf(CHAIN_ID.RULE.SVG)
.uses.has(CHAIN_ID.USE.SVGR),
);
if (isUsingSvgr) {
if (isUsingSvgr && !bundle) {
// in bundleless, only support transform the svg asset to mixedImport svgr file
// remove issuer to make every svg asset is transformed
const rule = config.module
.rule(CHAIN_ID.RULE.SVG)
.oneOf(CHAIN_ID.RULE.SVG);
.oneOf(CHAIN_ID.ONE_OF.SVG);
rule.issuer([]);
}
config
.plugin(LibAssetExtractPlugin.name)
.use(LibAssetExtractPlugin, [{ bundle, isUsingSvgr }]);

if (bundle) {
// preserve './' in css url
// https://github.com/web-infra-dev/rspack/pull/8946
config.plugins.get(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT)?.tap((options) => {
if (bundle) {
return [
{
...options[0],
enforceRelative: true,
},
];
}
return options;
});
}
});
},
});
Expand All @@ -43,13 +59,7 @@ export const composeAssetConfig = (
dataUriLimit: 0, // default: no inline asset
assetPrefix: 'auto',
},
tools: {
rspack: {
plugins: [
new LibAssetExtractPlugin({ bundle: true, isUsingSvgr: false }),
],
},
},
plugins: [pluginLibAsset({ bundle: true })],
};
}
return {
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/css/LibCssExtractPlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class LibCssExtractPlugin implements Rspack.RspackPluginInstance {
const undoPath = getUndoPath(
name,
compilation.outputOptions.path!,
false,
// https://github.com/web-infra-dev/rspack/pull/8946
true,
);
replace(`${ABSOLUTE_PUBLIC_PATH}${AUTO_PUBLIC_PATH}`, undoPath);
replace(ABSOLUTE_PUBLIC_PATH, '');
Expand Down
36 changes: 14 additions & 22 deletions packages/core/tests/__snapshots__/config.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
"name": "rsbuild:format",
"setup": [Function],
},
{
"name": "rsbuild:lib-asset",
"pre": [
"rsbuild:svgr",
],
"setup": [Function],
},
{
"name": "rsbuild:lib-entry-chunk",
"setup": [Function],
Expand Down Expand Up @@ -214,17 +221,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
{
"externalsType": "module-import",
},
{
"plugins": [
LibAssetExtractPlugin {
"name": "LIB_ASSET_EXTRACT_PLUGIN",
"options": {
"bundle": true,
"isUsingSvgr": false,
},
},
],
},
{
"plugins": [
EntryChunkPlugin {
Expand Down Expand Up @@ -369,6 +365,13 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
"name": "rsbuild:cjs-import-meta-url-shim",
"setup": [Function],
},
{
"name": "rsbuild:lib-asset",
"pre": [
"rsbuild:svgr",
],
"setup": [Function],
},
{
"name": "rsbuild:lib-entry-chunk",
"setup": [Function],
Expand Down Expand Up @@ -461,17 +464,6 @@ exports[`Should compose create Rsbuild config correctly > Merge Rsbuild config i
{
"externalsType": "commonjs-import",
},
{
"plugins": [
LibAssetExtractPlugin {
"name": "LIB_ASSET_EXTRACT_PLUGIN",
"options": {
"bundle": true,
"isUsingSvgr": false,
},
},
],
},
{
"plugins": [
EntryChunkPlugin {
Expand Down
1 change: 0 additions & 1 deletion tests/integration/asset/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ test('set the assets output path', async () => {
test('set the assets public path', async () => {
const fixturePath = join(__dirname, 'public-path');
const { contents } = await buildAndGetResults({ fixturePath });

// umd should preserve '__webpack_require__.p'
const { content: indexUmdJs } = queryContent(contents.umd!, /index\.js/);

Expand Down

0 comments on commit 51e29b8

Please sign in to comment.