Skip to content

Commit 00c9732

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

File tree

6 files changed

+42
-1
lines changed

6 files changed

+42
-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: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { RsbuildConfig } from "@rsbuild/core";
2+
import { Format } from "../types";
3+
4+
export const composeAssetConfig = (
5+
bundle: boolean,
6+
format: Format
7+
): RsbuildConfig => {
8+
if(format === 'esm' || format === 'cjs') {
9+
if(bundle) {
10+
return {
11+
output: {
12+
// default: no inline asset
13+
dataUriLimit: 0,
14+
assetPrefix: 'auto' // we currently not support import asset in js because of 'auto' publicPath runtime
15+
},
16+
}
17+
} else {
18+
// TODO: bundleless
19+
return {}
20+
}
21+
}
22+
23+
// mf and umd etc
24+
return {}
25+
};

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, format!);
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export const composeCssConfig = (
155155
bundle = true,
156156
): RsbuildConfig => {
157157
if (bundle || rootDir === null) {
158-
return {};
158+
return {}
159159
}
160160

161161
return {

0 commit comments

Comments
 (0)