Skip to content

Commit 6e67b32

Browse files
committed
feat(css): support asset in bundle
1 parent 2540150 commit 6e67b32

File tree

6 files changed

+44
-1
lines changed

6 files changed

+44
-1
lines changed
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
.counter-text {
22
font-size: 50px;
33
}
4+
5+
.title {
6+
background: url('./assets/logo.svg');
7+
}

examples/react-component-bundle/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const Counter: React.FC = () => {
88

99
return (
1010
<div>
11+
<h1 className='title'></h1>
1112
<h2 className="counter-text">Counter: {count}</h2>
1213
<CounterButton onClick={decrement} label="-" />
1314
<CounterButton onClick={increment} label="+" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { RsbuildConfig } from "@rsbuild/core";
2+
3+
export const composeAssetConfig = (
4+
bundle: boolean,
5+
): RsbuildConfig => {
6+
if(bundle) {
7+
return {
8+
output: {
9+
// default: no inline asset
10+
dataUriLimit: 0,
11+
},
12+
};
13+
}
14+
// TODO: bundleless
15+
return {}
16+
};

packages/core/src/config.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'node:fs';
22
import path, { dirname, extname, isAbsolute, join } from 'node:path';
3+
import { composeAssetConfig } from './asset/assetConfig'
34
import {
45
type EnvironmentConfig,
56
type RsbuildConfig,
@@ -1221,6 +1222,8 @@ async function composeLibRsbuildConfig(
12211222
cssModulesAuto,
12221223
);
12231224
const cssConfig = composeCssConfig(lcp, config.bundle);
1225+
const assetConfig = composeAssetConfig(bundle);
1226+
12241227
const entryChunkConfig = composeEntryChunkConfig({
12251228
enabledImportMetaUrlShim: enabledShims.cjs['import.meta.url'],
12261229
});
@@ -1251,6 +1254,7 @@ async function composeLibRsbuildConfig(
12511254
targetConfig,
12521255
entryConfig,
12531256
cssConfig,
1257+
assetConfig,
12541258
entryChunkConfig,
12551259
minifyConfig,
12561260
dtsConfig,

packages/core/src/css/cssConfig.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,18 @@ export const composeCssConfig = (
155155
bundle = true,
156156
): RsbuildConfig => {
157157
if (bundle || rootDir === null) {
158-
return {};
158+
return {
159+
tools: {
160+
bundlerChain(chain, {CHAIN_ID}) {
161+
chain.plugins.get(CHAIN_ID.PLUGIN.MINI_CSS_EXTRACT)?.tap(config => {
162+
return [{
163+
...(config?.[0] ?? {}),
164+
publicPath: 'auto',
165+
}]
166+
})
167+
}
168+
}
169+
};
159170
}
160171

161172
return {

0 commit comments

Comments
 (0)