Skip to content

Commit 4232b76

Browse files
committed
chore: save
1 parent 8b1d25e commit 4232b76

File tree

32 files changed

+354
-21
lines changed

32 files changed

+354
-21
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@import 'https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css';
2+
@import url('https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css');
3+
@import url('lib1.css');
4+
@import 'lib2.css';
5+
6+
.import {
7+
background-image: url('https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css')
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.lib1 {
2+
color: red;
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.lib2 {
2+
color: green;
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"extends": "@rslib/tsconfig/base",
3+
"compilerOptions": {
4+
"baseUrl": "./"
5+
},
6+
"include": ["src"]
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "css-bundle-false-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [generateBundleEsmConfig({bundle: false}),
6+
// generateBundleCjsConfig({bundle: false})
7+
],
8+
source: {
9+
entry: {
10+
index: ['../__fixtures__/src/**/*.css'],
11+
},
12+
},
13+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "css-bundle-test",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [generateBundleEsmConfig(), generateBundleCjsConfig()],
6+
source: {
7+
entry: {
8+
index: '../__fixtures__/src/import.css',
9+
},
10+
},
11+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!node_modules
2+
node_modules/.*
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
code {
2+
padding: 0.25em;
3+
line-height: 0;
4+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
ul,
2+
ol {
3+
text-align: left;
4+
5+
& & {
6+
padding: {
7+
bottom: 0;
8+
left: 0;
9+
}
10+
}
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background: url(./logo.svg);
3+
}
Lines changed: 7 additions & 0 deletions
Loading
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@import 'foundation/code', 'foundation/lists';
2+
@import '~lib1/index.css';
3+
@import './foundation/index.scss';
4+
5+
$url: './foundation/logo.svg';
6+
$border-dark: rgba($base-color, 0.88);
7+
8+
.url-variable {
9+
background: url($url);
10+
}
11+
12+
.alert {
13+
border: 1px solid $border-dark;
14+
}

e2e/cases/style/sass/bundle/node_modules/lib1/index.css

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

e2e/cases/style/sass/bundle/node_modules/lib1/package.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "sass-test",
3+
"version": "1.0.0",
4+
"private": true
5+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// import { defineConfig } from '';
2+
3+
export default defineConfig({
4+
buildConfig: {
5+
buildType: 'bundle',
6+
style: {
7+
sass: {
8+
sassOptions: {},
9+
additionalData: '$base-color: #c6538c;',
10+
},
11+
},
12+
asset: {
13+
limit: 0,
14+
},
15+
input: ['index.scss'],
16+
},
17+
});
18+
19+
20+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
21+
import { defineConfig } from '@rslib/core';
22+
23+
export default defineConfig({
24+
lib: [generateBundleEsmConfig({bundle: false}),
25+
// generateBundleCjsConfig({bundle: false})
26+
],
27+
tools: {
28+
29+
},
30+
source: {
31+
entry: {
32+
index: ['../__fixtures__/src/**/*.css'],
33+
},
34+
},
35+
plugins: [pluginSass()]
36+
});

e2e/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@e2e/helper": "workspace:*",
1313
"@playwright/test": "1.47.1",
1414
"@rsbuild/core": "1.0.4",
15+
"@rsbuild/plugin-sass": "1.0.1",
1516
"@rslib/core": "workspace:*",
1617
"@rslib/tsconfig": "workspace:*",
1718
"@types/fs-extra": "^11.0.4",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# @examples/react-component
2+
3+
This example demonstrates how to use Rslib to build a simple React component.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "@examples/react-component-bundle-false-sass",
3+
"private": true,
4+
"scripts": {
5+
"build": "rslib build"
6+
},
7+
"devDependencies": {
8+
"@rsbuild/plugin-react": "1.0.2",
9+
"@rsbuild/plugin-sass": "1.0.1",
10+
"@rslib/core": "workspace:*",
11+
"@types/react": "^18.3.5",
12+
"react": "^18.3.1"
13+
},
14+
"peerDependencies": {
15+
"react": "*"
16+
}
17+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { pluginReact } from '@rsbuild/plugin-react';
2+
import { type LibConfig, defineConfig } from '@rslib/core';
3+
import { pluginSass } from '@rsbuild/plugin-sass'
4+
5+
const shared: LibConfig = {
6+
bundle: false,
7+
};
8+
9+
export default defineConfig({
10+
source: {
11+
entry: {
12+
index: ['./src/**', '!./src/env.d.ts'],
13+
},
14+
},
15+
lib: [
16+
{
17+
...shared,
18+
format: 'esm',
19+
output: {
20+
distPath: {
21+
root: './dist/esm',
22+
// css: '.',
23+
// cssAsync: '.',
24+
},
25+
},
26+
bundle: false,
27+
},
28+
// {
29+
// ...shared,
30+
// format: 'cjs',
31+
// output: {
32+
// distPath: {
33+
// root: './dist/cjs',
34+
// css: '.',
35+
// cssAsync: '.',
36+
// },
37+
// },
38+
// bundle: false,
39+
// },
40+
],
41+
plugins: [pluginReact(), pluginSass()],
42+
output: {
43+
cssModules: {
44+
localIdentName: '[hash:base64:4]',
45+
},
46+
},
47+
tools: {
48+
cssLoader: {
49+
import: false
50+
}
51+
},
52+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.button {
2+
background: blue;
3+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import styles from './CounterButton.module.scss';
2+
interface CounterButtonProps {
3+
onClick: () => void;
4+
label: string;
5+
}
6+
7+
export const CounterButton: React.FC<CounterButtonProps> = ({
8+
onClick,
9+
label,
10+
}) => (
11+
<button type="button" className={styles.button} onClick={onClick}>
12+
{label}
13+
</button>
14+
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
declare module '*.module.css' {
2+
const classes: { [key: string]: string };
3+
export default classes;
4+
}
5+
6+
declare module '*.module.scss' {
7+
const classes: { [key: string]: string };
8+
export default classes;
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { CounterButton } from './CounterButton';
2+
import { useCounter } from './useCounter';
3+
import './reset.css';
4+
5+
export const Counter: React.FC = () => {
6+
const { count, increment, decrement } = useCounter();
7+
8+
return (
9+
<div>
10+
<h2>Counter: {count}</h2>
11+
<CounterButton onClick={decrement} label="-" />
12+
<CounterButton onClick={increment} label="+" />
13+
</div>
14+
);
15+
};
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.body {
2+
background: red;
3+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { useState } from 'react';
2+
3+
export const useCounter = (initialValue = 0) => {
4+
const [count, setCount] = useState(initialValue);
5+
6+
const increment = () => setCount((prev) => prev + 1);
7+
const decrement = () => setCount((prev) => prev - 1);
8+
9+
return { count, increment, decrement };
10+
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"compilerOptions": {
3+
"jsx": "react-jsx",
4+
"strict": true
5+
},
6+
"include": ["src/**/*"]
7+
}

packages/core/src/config.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,14 @@ const pluginLibCss = (rootDir: string): RsbuildPlugin => ({
642642
const composeCssConfig = (rootDir: string): RsbuildConfig => {
643643
return {
644644
plugins: [pluginLibCss(rootDir)],
645+
tools: {
646+
cssLoader: {
647+
// Otherwise, external variables will be executed by css-extract and cause an error.
648+
// e.g: `@import url('./a.css');`
649+
import: false,
650+
sourceMap: false
651+
}
652+
}
645653
};
646654
};
647655

@@ -740,31 +748,21 @@ const composeBundleConfig = (
740748
// This may result in a change in semantics,
741749
// user should use copy to keep origin file or use another separate entry to deal this
742750
let request: string = data.request;
751+
if(request[0] === '!') {
752+
return callback(null, request.slice(1));
753+
}
743754
if (request[0] === '.') {
744-
if (request.includes('compiled/css-loader')) {
755+
// @rsbuild/core/compiled/css-loader/noSourceMaps.js sourceMaps.js api.mjs etc.
756+
if (/compiled\/css-loader\//.test(request)) {
745757
return callback();
746758
}
747759

748-
const isCssModuleEmitted = request.endsWith('_module.css');
749-
if (isCssModuleEmitted) {
750-
return callback(null, request);
751-
}
752-
753760
const ext = extname(request);
754761
const isCssExt = ext === 'css';
755762
if (isCssExt && !isStyleRedirect) {
756763
return callback(null, request);
757764
}
758765

759-
// const jsExtensions = ['js', 'cjs', 'mjs', 'ts', 'mts', 'cts', 'jsx', 'tsx'];
760-
// const isNotJsExt = ext && !jsExtensions.includes(ext)
761-
762-
// 1. not js: css svg asset
763-
// if(isNotJsExt) {
764-
// return callback(null, request)
765-
// }
766-
767-
// 2. js or no ext
768766
request = ext
769767
? request.replace(/\.[^.]+$/, jsExtension)
770768
: `${request}${jsExtension}`;

0 commit comments

Comments
 (0)