MCPcopy
hub / github.com/tailwindlabs/tailwindcss / optimize

Function optimize

packages/@tailwindcss-node/src/optimize.ts:29–150  ·  view source on GitHub ↗
(
  input: string,
  { file = 'input.css', minify = false, map }: OptimizeOptions = {},
)

Source from the content-addressed store, hash-verified

27}
28
29export function optimize(
30 input: string,
31 { file = 'input.css', minify = false, map }: OptimizeOptions = {},
32): TransformResult {
33 function optimize(code: Buffer | Uint8Array, map: string | undefined) {
34 return transform({
35 filename: file,
36 code,
37 minify,
38 sourceMap: typeof map !== 'undefined',
39 inputSourceMap: map,
40 drafts: {
41 customMedia: true,
42 },
43 nonStandard: {
44 deepSelectorCombinator: true,
45 },
46 include: Features.Nesting | Features.MediaQueries,
47 exclude: Features.LogicalProperties | Features.DirSelector | Features.LightDark,
48 targets: {
49 safari: (16 << 16) | (4 << 8),
50 ios_saf: (16 << 16) | (4 << 8),
51 firefox: 128 << 16,
52 chrome: 111 << 16,
53 },
54 errorRecovery: true,
55 })
56 }
57
58 // Running Lightning CSS twice to ensure that adjacent rules are merged after
59 // nesting is applied. This creates a more optimized output.
60 let result = optimize(Buffer.from(input), map)
61 map = result.map?.toString()
62
63 result.warnings = result.warnings.filter((warning) => {
64 // Ignore warnings about unknown pseudo-classes as they are likely caused
65 // by the use of `:deep()`, `:slotted()`, and `:global()` which are not
66 // standard CSS but are commonly used in frameworks like Vue.
67 if (/'(deep|slotted|global)' is not recognized as a valid pseudo-/.test(warning.message)) {
68 return false
69 }
70
71 // Ignore warnings about unknown at-rules.
72 //
73 // TODO: drop `@position-try` once https://github.com/parcel-bundler/lightningcss/pull/1238 lands
74 if (/Unknown at rule: @position-try/.test(warning.message)) {
75 return false
76 }
77
78 return true
79 })
80
81 // Because of `errorRecovery: true`, there could be warnings, so let's let the
82 // user know about them.
83 if (process.env.NODE_ENV !== 'test' && result.warnings.length > 0) {
84 let lines = input.split('\n')
85
86 let output = [

Callers 4

runFunction · 0.90
renderFunction · 0.90
handlerFunction · 0.90
tailwindLoaderFunction · 0.90

Calls 4

yellowFunction · 0.85
dimFunction · 0.70
transformFunction · 0.50
entriesMethod · 0.45

Tested by 1

renderFunction · 0.72