Skip to content
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
19 changes: 19 additions & 0 deletions .changeset/add-css-sourcemap-option.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
"@lynx-js/rspeedy": patch
---

add a `sourceMap.css` option to emit CSS sourcemaps.

By default, `sourceMap.css` is false. You can set it to true to emit CSS sourcemaps.

```js
import { defineConfig } from '@lynx-js/rspeedy';

export default defineConfig({
output: {
sourceMap: {
css: true,
},
},
});
Comment thread
luhc228 marked this conversation as resolved.
```
1 change: 1 addition & 0 deletions packages/rspeedy/core/etc/rspeedy.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ export interface Source {

// @public
export interface SourceMap {
css?: boolean | undefined;
js?: Rspack.DevTool | undefined | `${Exclude<Rspack.DevTool, false | 'eval'>}-debugids`;
}

Expand Down
24 changes: 24 additions & 0 deletions packages/rspeedy/core/src/config/output/source-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,28 @@ export interface SourceMap {
| Rspack.DevTool
| undefined
| `${Exclude<Rspack.DevTool, false | 'eval'>}-debugids`

/**
* Whether to generate CSS source maps.
*
* @remarks
*
* Defaults to `false`.
*
* @example
*
* ```js
* import { defineConfig } from '@lynx-js/rspeedy'
*
* export default defineConfig({
* output: {
* sourceMap: {
* js: 'cheap-module-source-map',
* css: true,
* },
* },
* })
* ```
*/
css?: boolean | undefined
}
19 changes: 19 additions & 0 deletions packages/rspeedy/core/test/config/output.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -380,11 +380,30 @@ describe('Config - Output', () => {
},
})

assertType<Output>({
sourceMap: {
css: true,
},
})

assertType<Output>({
sourceMap: {
css: false,
},
})

assertType<Output>({
sourceMap: {
// @ts-expect-error should reject non-devtool value.
js: 'foo-bar',
},
})

assertType<Output>({
sourceMap: {
// @ts-expect-error should reject non-boolean value.
css: 'foo-bar',
},
})
})
})
22 changes: 22 additions & 0 deletions packages/rspeedy/core/test/config/validate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,11 @@ describe('Config Validation', () => {
{ legalComments: 'inline' },
{ legalComments: 'none' },
{ legalComments: 'linked' },
{ sourceMap: true },
{ sourceMap: false },
{ sourceMap: { js: 'cheap-module-source-map' } },
{ sourceMap: { css: true } },
{ sourceMap: { js: false, css: false } },
]

cases.forEach(output => {
Expand All @@ -927,6 +932,23 @@ describe('Config Validation', () => {
})

test('invalid type', () => {
expect(() =>
validate({
output: {
sourceMap: {
css: 'true',
},
},
})
).toThrowErrorMatchingInlineSnapshot(`
[Error: Invalid configuration.

Invalid config on \`$input.output.sourceMap.css\`.
- Expect to be (boolean | undefined)
- Got: string
]
`)

expect(() =>
validate({
output: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.app {
color: red;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { root, Suspense, lazy } from '@lynx-js/react'
import './index.css'

const LazyBundleComp = lazy(() => import('./lazy-bundle-comp.jsx'))

Expand Down
Loading
Loading