Skip to content

Commit 580248a

Browse files
committed
refactor: re-organize css
1 parent 7925dec commit 580248a

File tree

7 files changed

+35
-35
lines changed

7 files changed

+35
-35
lines changed

src/config/options.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { createDefu } from 'defu'
77
import isInCi from 'is-in-ci'
88
import { createDebug } from 'obug'
99
import { resolveClean } from '../features/clean.ts'
10-
import { resolveCssOptions } from '../features/css.ts'
10+
import { resolveCssOptions } from '../features/css/index.ts'
1111
import { resolveEntry } from '../features/entry.ts'
1212
import { hasExportsTypes } from '../features/pkg/exports.ts'
1313
import { resolveTarget } from '../features/target.ts'

src/config/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CopyEntry, CopyOptions, CopyOptionsFn } from '../features/copy.ts'
2-
import type { CssOptions } from '../features/css.ts'
2+
import type { CssOptions } from '../features/css/index.ts'
33
import type { DevtoolsOptions } from '../features/devtools.ts'
44
import type {
55
BuildContext,

src/features/css/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
export interface CssOptions {
2+
/**
3+
* Enable/disable CSS code splitting.
4+
* When set to `false`, all CSS in the entire project will be extracted into a single CSS file.
5+
* When set to `true`, CSS imported in async JS chunks will be preserved as chunks.
6+
* @default true
7+
*/
8+
splitting?: boolean
9+
10+
/**
11+
* Specify the name of the CSS file.
12+
* @default 'style.css'
13+
*/
14+
fileName?: string
15+
}
16+
17+
export const defaultCssBundleName = 'style.css'
18+
19+
export function resolveCssOptions(
20+
options: CssOptions = {},
21+
): Required<CssOptions> {
22+
return {
23+
splitting: options.splitting ?? true,
24+
fileName: options.fileName ?? defaultCssBundleName,
25+
}
26+
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { esbuildTargetToLightningCSS } from '../utils/lightningcss.ts'
2-
import type { ResolvedConfig } from '../config/index.ts'
1+
import { esbuildTargetToLightningCSS } from '../../utils/lightningcss.ts'
2+
import type { ResolvedConfig } from '../../config/index.ts'
33
import type { Plugin } from 'rolldown'
44

55
export async function LightningCSSPlugin(
Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,8 @@
11
import { RE_CSS } from 'rolldown-plugin-dts/filename'
2-
import type { ResolvedConfig } from '../config/index.ts'
2+
import { defaultCssBundleName } from './index.ts'
3+
import type { ResolvedConfig } from '../../config/index.ts'
34
import type { OutputAsset, OutputChunk, Plugin } from 'rolldown'
45

5-
export interface CssOptions {
6-
/**
7-
* Enable/disable CSS code splitting.
8-
* When set to `false`, all CSS in the entire project will be extracted into a single CSS file.
9-
* When set to `true`, CSS imported in async JS chunks will be preserved as chunks.
10-
* @default true
11-
*/
12-
splitting?: boolean
13-
14-
/**
15-
* Specify the name of the CSS file.
16-
* @default 'style.css'
17-
*/
18-
fileName?: string
19-
}
20-
21-
const defaultCssBundleName = 'style.css'
22-
23-
export function resolveCssOptions(
24-
options: CssOptions = {},
25-
): Required<CssOptions> {
26-
return {
27-
splitting: options.splitting ?? true,
28-
fileName: options.fileName ?? defaultCssBundleName,
29-
}
30-
}
31-
326
// Regular expressions for file matching
337
const RE_CSS_HASH = /-[\w-]+\.css$/
348
const RE_CHUNK_HASH = /-[\w-]+\.(m?js|cjs)$/

src/features/pkg/exports.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import path from 'node:path'
22
import process from 'node:process'
33
import { describe, test } from 'vitest'
44
import { globalLogger } from '../../utils/logger.ts'
5-
import { resolveCssOptions } from '../css.ts'
5+
import { resolveCssOptions } from '../css/index.ts'
66
import { generateExports as _generateExports } from './exports.ts'
77
import type { ResolvedConfig } from '../../config/types.ts'
88
import type { ChunksByFormat, RolldownChunk } from '../../utils/chunks.ts'

src/features/rolldown.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import { mergeUserOptions } from '../config/options.ts'
1616
import { lowestCommonAncestor } from '../utils/fs.ts'
1717
import { importWithError } from '../utils/general.ts'
1818
import { LogLevels } from '../utils/logger.ts'
19-
import { CssCodeSplitPlugin } from './css.ts'
19+
import { LightningCSSPlugin } from './css/lightningcss.ts'
20+
import { CssCodeSplitPlugin } from './css/splitting.ts'
2021
import { ExternalPlugin } from './external.ts'
21-
import { LightningCSSPlugin } from './lightningcss.ts'
2222
import { NodeProtocolPlugin } from './node-protocol.ts'
2323
import { resolveChunkAddon, resolveChunkFilename } from './output.ts'
2424
import { ReportPlugin } from './report.ts'

0 commit comments

Comments
 (0)