Skip to content

Commit 2c5eb02

Browse files
authored
feat: add rsbuild import asset as string example (#236)
1 parent 407004c commit 2c5eb02

File tree

10 files changed

+184
-5
lines changed

10 files changed

+184
-5
lines changed

pnpm-lock.yaml

Lines changed: 30 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rsbuild/query-raw/.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Local
2+
.DS_Store
3+
*.local
4+
*.log*
5+
6+
# Dist
7+
node_modules
8+
dist/
9+
10+
# IDE
11+
.vscode/*
12+
!.vscode/extensions.json
13+
.idea

rsbuild/query-raw/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Rsbuild Project
2+
3+
## Setup
4+
5+
Install the dependencies:
6+
7+
```bash
8+
pnpm install
9+
```
10+
11+
## Get Started
12+
13+
Start the dev server:
14+
15+
```bash
16+
pnpm dev
17+
```
18+
19+
Build the app for production:
20+
21+
```bash
22+
pnpm build
23+
```
24+
25+
Preview the production build locally:
26+
27+
```bash
28+
pnpm preview
29+
```

rsbuild/query-raw/package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "rsbuild-query-raw",
3+
"version": "1.0.0",
4+
"private": true,
5+
"scripts": {
6+
"build": "rsbuild build",
7+
"dev": "rsbuild dev --open",
8+
"preview": "rsbuild preview"
9+
},
10+
"dependencies": {
11+
"react": "^19.0.0",
12+
"react-dom": "^19.0.0"
13+
},
14+
"devDependencies": {
15+
"@rsbuild/core": "1.2.3",
16+
"@rsbuild/plugin-react": "^1.1.0",
17+
"@types/react": "^19.0.8",
18+
"@types/react-dom": "^19.0.3",
19+
"typescript": "^5.7.3"
20+
}
21+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { defineConfig } from '@rsbuild/core';
2+
import { pluginReact } from '@rsbuild/plugin-react';
3+
4+
export default defineConfig({
5+
plugins: [pluginReact()],
6+
tools: {
7+
rspack: (config, { rspack }) => {
8+
config.module?.rules?.push({
9+
resourceQuery: /raw/,
10+
type: 'asset/source',
11+
});
12+
config.plugins?.push(
13+
new rspack.NormalModuleReplacementPlugin(/\?raw$/, (resource) => {
14+
resource.request = '!' + resource.request;
15+
}),
16+
);
17+
},
18+
},
19+
});

rsbuild/query-raw/src/App.css

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
body {
2+
margin: 0;
3+
color: #fff;
4+
font-family: Inter, Avenir, Helvetica, Arial, sans-serif;
5+
background-image: linear-gradient(to bottom, #020917, #101725);
6+
}
7+
8+
.content {
9+
display: flex;
10+
min-height: 100vh;
11+
line-height: 1.1;
12+
text-align: center;
13+
flex-direction: column;
14+
justify-content: center;
15+
}
16+
17+
.content h1 {
18+
font-size: 3.6rem;
19+
font-weight: 700;
20+
}
21+
22+
.content p {
23+
font-size: 1.2rem;
24+
font-weight: 400;
25+
opacity: 0.5;
26+
}

rsbuild/query-raw/src/App.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import cssStr from './App.css?raw';
2+
import jsonStr from '../package.json?raw';
3+
4+
console.log('cssStr', cssStr);
5+
console.log('jsonStr', jsonStr);
6+
7+
const App = () => {
8+
return (
9+
<div className="content">
10+
<h1>Rsbuild with React</h1>
11+
<p>Start building amazing things with Rsbuild.</p>
12+
</div>
13+
);
14+
};
15+
16+
export default App;

rsbuild/query-raw/src/env.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
/// <reference types="@rsbuild/core/types" />
2+
3+
declare module '*?raw' {
4+
const content: string;
5+
export default content;
6+
}

rsbuild/query-raw/src/index.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import React from 'react';
2+
import ReactDOM from 'react-dom/client';
3+
import App from './App';
4+
5+
const root = ReactDOM.createRoot(document.getElementById('root')!);
6+
root.render(
7+
<React.StrictMode>
8+
<App />
9+
</React.StrictMode>,
10+
);

rsbuild/query-raw/tsconfig.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"compilerOptions": {
3+
"target": "ES2020",
4+
"lib": ["DOM", "ES2020"],
5+
"module": "ESNext",
6+
"jsx": "react-jsx",
7+
"strict": true,
8+
"skipLibCheck": true,
9+
"isolatedModules": true,
10+
"resolveJsonModule": true,
11+
"moduleResolution": "bundler"
12+
},
13+
"include": ["src"]
14+
}

0 commit comments

Comments
 (0)