Skip to content

Commit

Permalink
More stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
patricklafrance committed Dec 13, 2024
1 parent 4c9f421 commit 27b5414
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 3 deletions.
55 changes: 55 additions & 0 deletions docs/rsbuild/configure-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,61 @@ The `=== "true"` part of `"DEBUG": process.env.DEBUG === "true"` is very importa
By default, Rsbuild injects a few environment variables into the code using the [source.define](https://rsbuild.dev/guide/advanced/env-vars#using-define) option. For additional information about these default environment variables, refer to the Rsbuild [documentation](https://rsbuild.dev/guide/advanced/env-vars#default-variables).
!!!

## CSS modules typings

When you import CSS Modules in TypeScript code, TypeScript may prompt that the module is missing a type definition:

```bash
TS2307: Cannot find module './index.module.css' or its corresponding type declarations.
```

To fix this, you need to add a type declaration file for the CSS Modules, please create a `src/env.d.ts` file, and add the corresponding type declaration.

```ts env.d.ts
/// <reference types="@rsbuild/core/types" />
```

!!!info
Make sure the project have a dependency on `@rsbuild/core`.
!!!

### Monorepo

If your solution is a monorepo, ensure that projects referencing your packages that include CSS Modules, also include the necessary type definitions

For example, given the following structure:

``` !#3,7
workspace
├── app
├──── tsconfig.ts
├── packages
├──── components
├────── src
├───────── Button.tsx
├───────── Button.module.css
├───────── env.d.ts
├───────── tsconfig.ts
├── package.json
```

Copy the CSS Modules typings into the `app` web application own `env.d.ts` file, or include the `components` package's typings into the `apps` web application `tsconfig.ts` configuration file:

```json !#5 app/tsconfig.ts
{
"extends": "@workleap/typescript-configs/web-application.json",
"include": [
".",
"../**/src/env.d.ts"
],
"exclude": ["public", "dist", "node_modules"]
}
```

!!!info
For additional information abour CSS modules type declaration, refer to the Rsbuild [documentation](https://rsbuild.dev/guide/basic/css-modules#type-declaration).
!!!

## Try it :rocket:

To test your new Rsbuild configuration, open a terminal at the root of the project and execute the [CLI script added earlier](#add-a-cli-script). The build process should complete without outputting any error in the terminal and the bundle files should be available in the `/dist` folder (or any other `distPath` you configured).
33 changes: 33 additions & 0 deletions docs/rsbuild/configure-dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,39 @@ To fix this, you need to add a type declaration file for the CSS Modules, please
Make sure the project have a dependency on `@rsbuild/core`.
!!!

### Monorepo

If your solution is a monorepo, ensure that projects referencing your packages that include CSS Modules, also include the necessary type definitions

For example, given the following structure:

``` !#3,7
workspace
├── app
├──── tsconfig.ts
├── packages
├──── components
├────── src
├───────── Button.tsx
├───────── Button.module.css
├───────── env.d.ts
├───────── tsconfig.ts
├── package.json
```

Copy the CSS Modules typings into the `app` web application own `env.d.ts` file, or include the `components` package's typings into the `apps` web application `tsconfig.ts` configuration file:

```json !#5 app/tsconfig.ts
{
"extends": "@workleap/typescript-configs/web-application.json",
"include": [
".",
"../**/src/env.d.ts"
],
"exclude": ["public", "dist", "node_modules"]
}
```

!!!info
For additional information abour CSS modules type declaration, refer to the Rsbuild [documentation](https://rsbuild.dev/guide/basic/css-modules#type-declaration).
!!!
Expand Down
11 changes: 8 additions & 3 deletions docs/rsbuild/migrate-from-webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ Then, in the same terminal, remove the following packages:

+++ pnpm
```bash
pnpm remove @workleap/webpack-configs @swc/core @swc/helpers @workleap/swc-configs webpack webpack-cli webpack-dev-server
pnpm remove @workleap/webpack-configs @swc/core @swc/helpers @workleap/swc-configs webpack webpack-cli webpack-dev-server @workleap/postcss-configs postcss
```
+++ yarn
```bash
yarn remove @workleap/webpack-configs @swc/core @swc/helpers @workleap/swc-configs webpack webpack-cli webpack-dev-server
yarn remove @workleap/webpack-configs @swc/core @swc/helpers @workleap/swc-configs webpack webpack-cli webpack-dev-server @workleap/postcss-configs postcss
```
+++ npm
```bash
npm uninstall @workleap/webpack-configs @swc/core @swc/helpers @workleap/swc-configs webpack webpack-cli webpack-dev-server
npm uninstall @workleap/webpack-configs @swc/core @swc/helpers @workleap/swc-configs webpack webpack-cli webpack-dev-server @workleap/postcss-configs postcss
```
+++

Expand All @@ -57,6 +57,7 @@ web-app
├──── index.html --> U
├── webpack.dev.js --> rsbuild.dev.ts
├── webpack.build.js --> rsbuild.build.ts
├── postcss.config.ts --> X
├── swc.build.js --> X
├── swc.dev.js --> X
├── package.json
Expand Down Expand Up @@ -122,6 +123,10 @@ import { defineDevHostConfig } from "@workleap/rsbuild-configs";
export default defineDevHostConfig(8080);
```

### `postcss.config.ts`

Delete the `postcss.config.ts` file.

### `swc.build.js`

Delete the `swc.build.js` file.
Expand Down

0 comments on commit 27b5414

Please sign in to comment.