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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Support sorting in callable template literals ([#367](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/367))
- Support sorting in function calls mixed with property accesses ([#367](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/367))
- Handle quote escapes in LESS when sorting `@apply` ([#392](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/392))
- Improved monorepo support by loading Tailwind CSS relative to the input file instead of prettier config file ([#386](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/386))
- Improved monorepo support by loading v3 configs relative to the input file instead of prettier config file ([#386](https://github.com/tailwindlabs/prettier-plugin-tailwindcss/pull/386))

## [0.6.14] - 2025-07-09

Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@ This plugin uses Prettier APIs that can only be used by one plugin at a time, ma
- `prettier-plugin-multiline-arrays`
- `prettier-plugin-organize-attributes`
- `prettier-plugin-organize-imports`
- `prettier-plugin-style-order`
- `prettier-plugin-svelte`
- `prettier-plugin-sort-imports`

Expand Down
44 changes: 43 additions & 1 deletion build.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as fs from 'node:fs'
import { readFile } from 'node:fs/promises'
import * as path from 'node:path'
import { fileURLToPath } from 'node:url'
import esbuild from 'esbuild'
Expand Down Expand Up @@ -62,6 +63,47 @@ function patchCjsInterop() {
}
}

/**
* @returns {import('esbuild').Plugin}
*/
function inlineCssImports() {
return {
name: 'inline-css-imports',
setup(build) {
// Inline CSS imports
build.onLoad({ filter: /\.css$/ }, async (args) => {
let content = await readFile(args.path, 'utf-8')

return {
loader: 'js',
contents: `export default ${JSON.stringify(content)}`,
}
})

// Inline preflight in v3
// TODO: This needs a test
build.onLoad({ filter: /corePlugins\.js$/ }, async (args) => {
let preflightPath = path.resolve(path.dirname(args.path), './css/preflight.css')
let preflightContent = await readFile(preflightPath, 'utf-8')

let content = await readFile(args.path, 'utf-8')

// This is a bit fragile but this is to inline preflight for the
// *bundled* version which means a failing test should be enough
content = content.replace(
`_fs.default.readFileSync(_path.join(__dirname, "./css/preflight.css"), "utf8")`,
JSON.stringify(preflightContent),
)

return {
loader: 'js',
contents: content,
}
})
},
}
}

const __dirname = path.dirname(fileURLToPath(import.meta.url))

let context = await esbuild.context({
Expand All @@ -73,7 +115,7 @@ let context = await esbuild.context({
entryPoints: [path.resolve(__dirname, './src/index.js')],
outfile: path.resolve(__dirname, './dist/index.mjs'),
format: 'esm',
plugins: [patchRecast(), patchCjsInterop()],
plugins: [patchRecast(), patchCjsInterop(), inlineCssImports()],
})

await context.rebuild()
Expand Down
Loading