Skip to content

Commit c3fc11e

Browse files
committed
chore: init basic needs
1 parent 6291f9f commit c3fc11e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+1005
-6
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: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { generateBundleCjsConfig, generateBundleEsmConfig } from '@e2e/helper';
2+
import { defineConfig } from '@rslib/core';
3+
4+
export default defineConfig({
5+
lib: [
6+
generateBundleEsmConfig({ bundle: false }),
7+
generateBundleCjsConfig({ bundle: false }),
8+
],
9+
source: {
10+
entry: {
11+
index: ['../__fixtures__/src/**/*.css'],
12+
},
13+
},
14+
});
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+
});

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+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
!node_modules
2+
node_modules/.*

e2e/cases/style/sass/__fixtures__/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/__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: 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: 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+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "sass-bundle-test",
3+
"version": "1.0.0",
4+
"private": true
5+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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: [generateBundleEsmConfig(), generateBundleCjsConfig()],
7+
tools: {},
8+
source: {
9+
entry: {
10+
index: ['../__fixtures__/src/index.scss'],
11+
},
12+
},
13+
plugins: [
14+
pluginSass({
15+
sassLoaderOptions: {
16+
additionalData: '$base-color: #c6538c;',
17+
},
18+
}),
19+
],
20+
});

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+
});

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.2",
1414
"@rsbuild/core": "1.0.5",
15+
"@rsbuild/plugin-sass": "1.0.1",
1516
"@rslib/core": "workspace:*",
1617
"@rslib/tsconfig": "workspace:*",
1718
"@types/fs-extra": "^11.0.4",
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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import { pluginReact } from '@rsbuild/plugin-react';
2+
import { pluginSass } from '@rsbuild/plugin-sass';
3+
import { type LibConfig, defineConfig } from '@rslib/core';
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+
});
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+
}

examples/react-component/src/index.tsx renamed to examples/react-component-bundle-false-sass/src/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { CounterButton } from './CounterButton';
22
import { useCounter } from './useCounter';
3+
import './reset.css';
34

45
export const Counter: React.FC = () => {
56
const { count, increment, decrement } = useCounter();
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: 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+
}

0 commit comments

Comments
 (0)