Skip to content

Commit 238dfd3

Browse files
committed
chore: save
1 parent 4232b76 commit 238dfd3

File tree

26 files changed

+215
-110
lines changed

26 files changed

+215
-110
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
@import 'https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css';
22
@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';
3+
@import url('lib1.css');
4+
@import 'lib2.css';
55

66
.import {
7-
background-image: url('https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css')
7+
background-image: url('https://cdnjs.cloudflare.com/ajax/libs/modern-normalize/1.1.0/modern-normalize.css');
88
}

e2e/cases/style/css/bundle-false/rslib.config.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
22
import { defineConfig } from '@rslib/core';
33

44
export default defineConfig({
5-
lib: [generateBundleEsmConfig({bundle: false}),
6-
// generateBundleCjsConfig({bundle: false})
5+
lib: [
6+
generateBundleEsmConfig({ bundle: false }),
7+
generateBundleCjsConfig({ bundle: false }),
78
],
89
source: {
910
entry: {

e2e/cases/style/css/index.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { join } from 'node:path';
2+
import { buildAndGetResults } from '@e2e/helper';
3+
import { expect, test } from 'vitest';
4+
5+
test('should extract css when set bundle: true', async () => {
6+
const fixturePath = join(__dirname, 'bundle');
7+
const { contents } = await buildAndGetResults(fixturePath, 'css');
8+
const esmFiles = Object.keys(contents.esm);
9+
expect(esmFiles).toMatchInlineSnapshot(`
10+
[
11+
"<ROOT>/cases/style/css/bundle/dist/esm/static/css/index.css",
12+
]
13+
`);
14+
15+
const cjsFiles = Object.keys(contents.cjs);
16+
expect(cjsFiles).toMatchInlineSnapshot(`
17+
[
18+
"<ROOT>/cases/style/css/bundle/dist/cjs/static/css/index.css",
19+
]
20+
`);
21+
});
22+
23+
test('should extract css when set bundle: false', async () => {
24+
const fixturePath = join(__dirname, 'bundle-false');
25+
const { contents } = await buildAndGetResults(fixturePath, 'css');
26+
const esmFiles = Object.keys(contents.esm);
27+
28+
expect(esmFiles).toMatchInlineSnapshot(`
29+
[
30+
"<ROOT>/cases/style/css/bundle-false/dist/esm/import.css",
31+
"<ROOT>/cases/style/css/bundle-false/dist/esm/lib1.css",
32+
"<ROOT>/cases/style/css/bundle-false/dist/esm/lib2.css",
33+
]
34+
`);
35+
36+
const cjsFiles = Object.keys(contents.cjs);
37+
expect(cjsFiles).toMatchInlineSnapshot(`
38+
[
39+
"<ROOT>/cases/style/css/bundle-false/dist/cjs/import.css",
40+
"<ROOT>/cases/style/css/bundle-false/dist/cjs/lib1.css",
41+
"<ROOT>/cases/style/css/bundle-false/dist/cjs/lib2.css",
42+
]
43+
`);
44+
});

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

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
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: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@import 'foundation/code', 'foundation/lists';
2+
// TODO: Error: Sass variables aren't allowed in plain CSS.
3+
// @import '~lib1/index.css';
4+
@import './foundation/index.scss';
5+
6+
// TODO: asset support
7+
// $url: './foundation/logo.svg';
8+
$border-dark: rgba($base-color, 0.88);
9+
10+
// .url-variable {
11+
// background: url($url);
12+
// }
13+
14+
.alert {
15+
border: 1px solid $border-dark;
16+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "sass-bundle-false-test",
3+
"version": "1.0.0",
4+
"private": true
5+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { pluginSass } from '@rsbuild/plugin-sass';
3+
import { defineConfig } from '@rslib/core';
4+
5+
export default defineConfig({
6+
lib: [
7+
generateBundleEsmConfig({ bundle: false }),
8+
generateBundleCjsConfig({ bundle: false }),
9+
],
10+
tools: {},
11+
source: {
12+
entry: {
13+
index: [
14+
'../__fixtures__/src/**/*.scss',
15+
// TODO: assets support
16+
// '../__fixtures__/foundation/logo.svg'
17+
],
18+
},
19+
},
20+
plugins: [
21+
pluginSass({
22+
sassLoaderOptions: {
23+
additionalData: '$base-color: #c6538c;',
24+
},
25+
}),
26+
],
27+
});

e2e/cases/style/sass/bundle/foundation/index.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

e2e/cases/style/sass/bundle/index.scss

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"name": "sass-test",
2+
"name": "sass-bundle-test",
33
"version": "1.0.0",
44
"private": true
55
}
Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,20 @@
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-
201
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { pluginSass } from '@rsbuild/plugin-sass';
213
import { defineConfig } from '@rslib/core';
224

235
export default defineConfig({
24-
lib: [generateBundleEsmConfig({bundle: false}),
25-
// generateBundleCjsConfig({bundle: false})
26-
],
27-
tools: {
28-
29-
},
6+
lib: [generateBundleEsmConfig(), generateBundleCjsConfig()],
7+
tools: {},
308
source: {
319
entry: {
32-
index: ['../__fixtures__/src/**/*.css'],
10+
index: ['../__fixtures__/src/index.scss'],
3311
},
3412
},
35-
plugins: [pluginSass()]
13+
plugins: [
14+
pluginSass({
15+
sassLoaderOptions: {
16+
additionalData: '$base-color: #c6538c;',
17+
},
18+
}),
19+
],
3620
});

e2e/cases/style/sass/index.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { join } from 'node:path';
2+
import { buildAndGetResults } from '@e2e/helper';
3+
import { expect, test } from 'vitest';
4+
5+
test('should extract css with pluginSass when set bundle: true', async () => {
6+
const fixturePath = join(__dirname, 'bundle');
7+
const { contents } = await buildAndGetResults(fixturePath, 'css');
8+
const esmFiles = Object.keys(contents.esm);
9+
expect(esmFiles).toMatchInlineSnapshot(`
10+
[
11+
"<ROOT>/cases/style/sass/bundle/dist/esm/static/css/index.css",
12+
]
13+
`);
14+
15+
const cjsFiles = Object.keys(contents.cjs);
16+
expect(cjsFiles).toMatchInlineSnapshot(`
17+
[
18+
"<ROOT>/cases/style/sass/bundle/dist/cjs/static/css/index.css",
19+
]
20+
`);
21+
});
22+
23+
test('should extract css with pluginSass when set bundle: false', async () => {
24+
const fixturePath = join(__dirname, 'bundle-false');
25+
const { contents } = await buildAndGetResults(fixturePath, 'css');
26+
const esmFiles = Object.keys(contents.esm);
27+
28+
expect(esmFiles).toMatchInlineSnapshot(`
29+
[
30+
"<ROOT>/cases/style/sass/bundle-false/dist/esm/foundation/_code.css",
31+
"<ROOT>/cases/style/sass/bundle-false/dist/esm/foundation/_lists.css",
32+
"<ROOT>/cases/style/sass/bundle-false/dist/esm/index.css",
33+
]
34+
`);
35+
36+
const cjsFiles = Object.keys(contents.cjs);
37+
expect(cjsFiles).toMatchInlineSnapshot(`
38+
[
39+
"<ROOT>/cases/style/sass/bundle-false/dist/cjs/foundation/_code.css",
40+
"<ROOT>/cases/style/sass/bundle-false/dist/cjs/foundation/_lists.css",
41+
"<ROOT>/cases/style/sass/bundle-false/dist/cjs/index.css",
42+
]
43+
`);
44+
});
Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { pluginReact } from '@rsbuild/plugin-react';
2+
import { pluginSass } from '@rsbuild/plugin-sass';
23
import { type LibConfig, defineConfig } from '@rslib/core';
3-
import { pluginSass } from '@rsbuild/plugin-sass'
44

55
const shared: LibConfig = {
66
bundle: false,
@@ -25,28 +25,23 @@ export default defineConfig({
2525
},
2626
bundle: false,
2727
},
28-
// {
29-
// ...shared,
30-
// format: 'cjs',
31-
// output: {
32-
// distPath: {
33-
// root: './dist/cjs',
34-
// css: '.',
35-
// cssAsync: '.',
36-
// },
37-
// },
38-
// bundle: false,
39-
// },
28+
{
29+
...shared,
30+
format: 'cjs',
31+
output: {
32+
distPath: {
33+
root: './dist/cjs',
34+
css: '.',
35+
cssAsync: '.',
36+
},
37+
},
38+
bundle: false,
39+
},
4040
],
4141
plugins: [pluginReact(), pluginSass()],
4242
output: {
4343
cssModules: {
4444
localIdentName: '[hash:base64:4]',
4545
},
4646
},
47-
tools: {
48-
cssLoader: {
49-
import: false
50-
}
51-
},
5247
});

examples/react-component-bundle-false/rslib.config.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ export default defineConfig({
2424
},
2525
bundle: false,
2626
},
27-
// {
28-
// ...shared,
29-
// format: 'cjs',
30-
// output: {
31-
// distPath: {
32-
// root: './dist/cjs',
33-
// css: '.',
34-
// cssAsync: '.',
35-
// },
36-
// },
37-
// bundle: false,
38-
// },
27+
{
28+
...shared,
29+
format: 'cjs',
30+
output: {
31+
distPath: {
32+
root: './dist/cjs',
33+
css: '.',
34+
cssAsync: '.',
35+
},
36+
},
37+
bundle: false,
38+
},
3939
],
4040
plugins: [pluginReact()],
4141
});

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
"prebundle": "nx run-many -t prebundle",
1818
"prepare": "pnpm run build && simple-git-hooks",
1919
"sort-package-json": "npx sort-package-json \"packages/*/package.json\"",
20-
"test:artifact": "vitest run --project artifact",
21-
"test:artifact:watch": "vitest --project artifact",
20+
"test:artifact": "vitest run --project artifact --passWithNoTests",
21+
"test:artifact:watch": "vitest --project artifact --passWithNoTests ",
2222
"test:e2e": "cd e2e && pnpm run test",
2323
"test:unit": "vitest run --project unit*",
2424
"test:unit:watch": "vitest --project unit*",

packages/core/src/config.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,9 +647,8 @@ const composeCssConfig = (rootDir: string): RsbuildConfig => {
647647
// Otherwise, external variables will be executed by css-extract and cause an error.
648648
// e.g: `@import url('./a.css');`
649649
import: false,
650-
sourceMap: false
651-
}
652-
}
650+
},
651+
},
653652
};
654653
};
655654

@@ -748,7 +747,7 @@ const composeBundleConfig = (
748747
// This may result in a change in semantics,
749748
// user should use copy to keep origin file or use another separate entry to deal this
750749
let request: string = data.request;
751-
if(request[0] === '!') {
750+
if (request[0] === '!') {
752751
return callback(null, request.slice(1));
753752
}
754753
if (request[0] === '.') {

0 commit comments

Comments
 (0)