Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support css in bundless mode #206

Merged
merged 20 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ doc_build
**/*.js
**/*.ts
**/*.jsx
**/*.tsx
**/*.tsx

# ignore pnpm-lock
pnpm-lock.yaml
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,14 @@
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[css]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[sass]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[less]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"typescript.tsdk": "node_modules/typescript/lib"
}
5 changes: 5 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@
"enabled": false
}
},
"css": {
"formatter": {
"enabled": false
}
},
SoonIter marked this conversation as resolved.
Show resolved Hide resolved
"linter": {
"enabled": true,
"ignore": ["./tests/integration/**/*/src/*"],
Expand Down
20 changes: 20 additions & 0 deletions examples/react-component-bundle-false/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "@examples/react-component-bundle-false",
"private": true,
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
"types": "./dist/cjs/index.d.ts",
"scripts": {
"build": "rslib build"
},
"devDependencies": {
"@rsbuild/plugin-react": "^1.0.2",
"@rsbuild/plugin-sass": "^1.0.1",
"@rslib/core": "workspace:*",
"@types/react": "^18.3.5",
"react": "^18.3.1"
},
"peerDependencies": {
"react": "*"
}
}
39 changes: 39 additions & 0 deletions examples/react-component-bundle-false/rslib.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';
import { type LibConfig, defineConfig } from '@rslib/core';

const shared: LibConfig = {
bundle: false,
dts: {
bundle: false,
},
};

export default defineConfig({
source: {
entry: {
index: ['./src/**', '!./src/env.d.ts'],
},
},
lib: [
{
...shared,
format: 'esm',
output: {
distPath: {
root: './dist/esm',
},
},
},
{
...shared,
format: 'cjs',
output: {
distPath: {
root: './dist/cjs',
},
},
},
],
plugins: [pluginReact(), pluginSass()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.button {
background: yellow;
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import styles from './index.module.scss';
interface CounterButtonProps {
onClick: () => void;
label: string;
Expand All @@ -7,7 +8,7 @@ export const CounterButton: React.FC<CounterButtonProps> = ({
onClick,
label,
}) => (
<button type="button" onClick={onClick}>
<button type="button" className={styles.button} onClick={onClick}>
{label}
</button>
);
4 changes: 4 additions & 0 deletions examples/react-component-bundle-false/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.module.scss' {
const classes: { [key: string]: string };
export default classes;
}
3 changes: 3 additions & 0 deletions examples/react-component-bundle-false/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.counter-text {
font-size: 50px;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { CounterButton } from './CounterButton';
import { CounterButton } from './components/CounterButton/index';
import { useCounter } from './useCounter';
import './index.scss';

export const Counter: React.FC = () => {
const { count, increment, decrement } = useCounter();

return (
<div>
<h2>Counter: {count}</h2>
<h2 className="counter-text">Counter: {count}</h2>
<CounterButton onClick={decrement} label="-" />
<CounterButton onClick={increment} label="+" />
</div>
Expand Down
20 changes: 20 additions & 0 deletions examples/react-component-bundle-false/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"declaration": true,
"emitDeclarationOnly": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["DOM", "ESNext"],
"moduleResolution": "node",
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"strict": true
},
"exclude": ["**/node_modules"],
"include": ["src"]
}
3 changes: 3 additions & 0 deletions examples/react-component-bundle/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @examples/react-component

This example demonstrates how to use Rslib to build a simple React component.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@examples/react-component",
"name": "@examples/react-component-bundle",
"private": true,
"main": "./dist/cjs/index.js",
"module": "./dist/esm/index.mjs",
Expand All @@ -9,6 +9,7 @@
},
"devDependencies": {
"@rsbuild/plugin-react": "1.0.3",
"@rsbuild/plugin-sass": "^1.0.1",
"@rslib/core": "workspace:*",
"@types/react": "^18.3.11",
"react": "^18.3.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { pluginReact } from '@rsbuild/plugin-react';
import { pluginSass } from '@rsbuild/plugin-sass';
import { defineConfig } from '@rslib/core';

const shared = {
Expand All @@ -15,6 +16,8 @@ export default defineConfig({
output: {
distPath: {
root: './dist/esm',
css: '.',
cssAsync: '.',
},
},
},
Expand All @@ -24,9 +27,11 @@ export default defineConfig({
output: {
distPath: {
root: './dist/cjs',
css: '.',
cssAsync: '.',
},
},
},
],
plugins: [pluginReact()],
plugins: [pluginReact(), pluginSass()],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.button {
background: yellow;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import styles from './index.module.scss';
interface CounterButtonProps {
onClick: () => void;
label: string;
}

export const CounterButton: React.FC<CounterButtonProps> = ({
onClick,
label,
}) => (
<button type="button" className={styles.button} onClick={onClick}>
{label}
</button>
);
4 changes: 4 additions & 0 deletions examples/react-component-bundle/src/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
declare module '*.module.scss' {
const classes: { [key: string]: string };
export default classes;
}
3 changes: 3 additions & 0 deletions examples/react-component-bundle/src/index.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.counter-text {
font-size: 50px;
}
15 changes: 15 additions & 0 deletions examples/react-component-bundle/src/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { CounterButton } from './components/CounterButton/index';
import { useCounter } from './useCounter';
import './index.scss';

export const Counter: React.FC = () => {
const { count, increment, decrement } = useCounter();

return (
<div>
<h2 className="counter-text">Counter: {count}</h2>
<CounterButton onClick={decrement} label="-" />
<CounterButton onClick={increment} label="+" />
</div>
);
};
10 changes: 10 additions & 0 deletions examples/react-component-bundle/src/useCounter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { useState } from 'react';

export const useCounter = (initialValue = 0) => {
const [count, setCount] = useState(initialValue);

const increment = () => setCount((prev) => prev + 1);
const decrement = () => setCount((prev) => prev - 1);

return { count, increment, decrement };
};
20 changes: 20 additions & 0 deletions examples/react-component-bundle/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"allowJs": true,
"baseUrl": ".",
"declaration": true,
"emitDeclarationOnly": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "react-jsx",
"lib": ["DOM", "ESNext"],
"moduleResolution": "node",
"resolveJsonModule": true,
"rootDir": "src",
"skipLibCheck": true,
"strict": true
},
"exclude": ["**/node_modules"],
"include": ["src"]
}
8 changes: 0 additions & 8 deletions examples/react-component/tsconfig.json

This file was deleted.

1 change: 1 addition & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"devDependencies": {
"@rslib/tsconfig": "workspace:*",
"@rspack/core": "1.0.8",
fi3ework marked this conversation as resolved.
Show resolved Hide resolved
"@types/fs-extra": "^11.0.4",
"commander": "^12.1.0",
"fast-glob": "^3.3.2",
Expand Down
4 changes: 4 additions & 0 deletions packages/core/rslib.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export default defineConfig({
},
],
source: {
entry: {
index: './src/index.ts',
libCssExtractLoader: './src/css/libCssExtractLoader.ts',
},
define: {
RSLIB_VERSION: JSON.stringify(require('./package.json').version),
},
Expand Down
Loading
Loading