Skip to content

Commit

Permalink
fix(css): spread lightningcss options (#14024)
Browse files Browse the repository at this point in the history
Co-authored-by: Arnaud Barré <arnaud.barre@carbometrix.com>
  • Loading branch information
bru02 and ArnaudBarre authored Aug 14, 2023
1 parent 13ea794 commit 63a4451
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 57 deletions.
2 changes: 0 additions & 2 deletions packages/vite/api-extractor.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

"mainEntryPointFilePath": "./temp/node/index.d.ts",

"bundledPackages": ["lightningcss"],

"dtsRollup": {
"enabled": true,
"untrimmedFilePath": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"build-types": "run-s build-types-temp build-types-pre-patch build-types-roll build-types-post-patch build-types-check",
"build-types-temp": "tsc --emitDeclarationOnly --outDir temp/node -p src/node",
"build-types-pre-patch": "tsx scripts/prePatchTypes.ts",
"build-types-roll": "tsx scripts/api-extractor.ts run && rimraf temp",
"build-types-roll": "api-extractor run && rimraf temp",
"build-types-post-patch": "tsx scripts/postPatchTypes.ts",
"build-types-check": "tsx scripts/checkBuiltTypes.ts && tsc --project tsconfig.check.json",
"typecheck": "tsc --noEmit",
Expand Down
25 changes: 0 additions & 25 deletions packages/vite/scripts/api-extractor.ts

This file was deleted.

4 changes: 3 additions & 1 deletion packages/vite/scripts/checkBuiltTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const distDir = resolve(dir, '../dist')
const pkgJson = JSON.parse(
readFileSync(resolve(dir, '../package.json'), 'utf-8'),
)
const deps = new Set(Object.keys(pkgJson.dependencies))
const deps = new Set(
Object.keys(Object.assign(pkgJson.dependencies, pkgJson.peerDependencies)),
)

type SpecifierError = {
loc: SourceLocation | null | undefined
Expand Down
2 changes: 1 addition & 1 deletion packages/vite/src/node/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export type {
export type {
CSSOptions,
CSSModulesOptions,
LightningCSSOptions,
PreprocessCSSResult,
ResolvedCSSOptions,
} from './plugins/css'
Expand Down Expand Up @@ -144,4 +145,3 @@ export type { Terser } from 'dep-types/terser'
export type { RollupCommonJSOptions } from 'dep-types/commonjs'
export type { RollupDynamicImportVarsOptions } from 'dep-types/dynamicImportVars'
export type { Matcher, AnymatchPattern, AnymatchFn } from 'dep-types/anymatch'
export type { LightningCSSOptions } from 'dep-types/lightningcss'
14 changes: 10 additions & 4 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import type Sass from 'sass'
import type Stylus from 'stylus'
import type Less from 'less'
import type { Alias } from 'dep-types/alias'
import type { LightningCSSOptions } from 'dep-types/lightningcss'
import type { TransformOptions } from 'esbuild'
import { formatMessages, transform } from 'esbuild'
import type { RawSourceMap } from '@ampproject/remapping'
import type { BundleAsyncOptions, CustomAtRules } from 'lightningcss'
import { getCodeWithSourcemap, injectSourcesContent } from '../server/sourcemap'
import type { ModuleNode } from '../server/moduleGraph'
import type { ResolveFn, ViteDevServer } from '../'
Expand Down Expand Up @@ -139,6 +139,12 @@ export type ResolvedCSSOptions = Omit<CSSOptions, 'lightningcss'> & {
}
}

// remove options set by Vite
export type LightningCSSOptions = Omit<
BundleAsyncOptions<CustomAtRules>,
'filename' | 'resolver' | 'minify' | 'sourceMap' | 'analyzeDependencies'
>

export function resolveCSSOptions(
options: CSSOptions | undefined,
): ResolvedCSSOptions | undefined {
Expand Down Expand Up @@ -2167,13 +2173,15 @@ async function compileLightningCSS(
? (await importLightningCSS()).transformStyleAttribute({
filename,
code: Buffer.from(src),
targets: config.css?.lightningcss?.targets,
minify: config.isProduction && !!config.build.cssMinify,
targets: config.css?.lightningcss?.targets,
analyzeDependencies: true,
visitor: config.css?.lightningcss?.visitor,
})
: await (
await importLightningCSS()
).bundleAsync({
...config.css?.lightningcss,
filename,
resolver: {
read(filePath) {
Expand Down Expand Up @@ -2204,14 +2212,12 @@ async function compileLightningCSS(
return id
},
},
targets: config.css?.lightningcss?.targets,
minify: config.isProduction && !!config.build.cssMinify,
sourceMap: config.css?.devSourcemap,
analyzeDependencies: true,
cssModules: cssModuleRE.test(id)
? config.css?.lightningcss?.cssModules ?? true
: undefined,
drafts: config.css?.lightningcss?.drafts,
})

let css = res.code.toString()
Expand Down
23 changes: 0 additions & 23 deletions packages/vite/src/types/lightningcss.d.ts

This file was deleted.

0 comments on commit 63a4451

Please sign in to comment.