Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for basic addVariant plugins with new @plugin directive #13982

Merged
merged 17 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Duplicate loadPlugin implementation instead of exporting io file
  • Loading branch information
adamwathan committed Jul 10, 2024
commit d2495ce8daa222c3dd5ffb6aa0cd95902200d8cd
11 changes: 9 additions & 2 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import path from 'node:path'
import postcss from 'postcss'
import atImport from 'postcss-import'
import * as tailwindcss from 'tailwindcss'
import { loadPlugin } from 'tailwindcss/io'
import type { Arg, Result } from '../../utils/args'
import {
eprintln,
Expand Down Expand Up @@ -127,9 +126,17 @@ export async function handle(args: Result<ReturnType<typeof options>>) {

let inputFile = args['--input'] && args['--input'] !== '-' ? args['--input'] : process.cwd()

let basePath = path.dirname(path.resolve(inputFile))

function compile(css: string) {
return tailwindcss.compile(css, {
loadPlugin: loadPlugin(inputFile),
loadPlugin: (pluginPath) => {
if (pluginPath[0] === '.') {
return require(path.resolve(basePath, pluginPath))
}

return require(pluginPath)
},
})
}

Expand Down
11 changes: 9 additions & 2 deletions packages/@tailwindcss-postcss/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { scanDir } from '@tailwindcss/oxide'
import fs from 'fs'
import { Features, transform } from 'lightningcss'
import path from 'path'
import postcss, { type AcceptedPlugin, type PluginCreator } from 'postcss'
import postcssImport from 'postcss-import'
import { compile } from 'tailwindcss'
import { loadPlugin } from 'tailwindcss/io'

/**
* A Map that can generate default values for keys that don't exist.
Expand Down Expand Up @@ -131,8 +131,15 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
}

if (rebuildStrategy === 'full') {
let basePath = path.dirname(path.resolve(inputFile))
let { build } = compile(root.toString(), {
loadPlugin: loadPlugin(inputFile),
loadPlugin: (pluginPath) => {
if (pluginPath[0] === '.') {
return require(path.resolve(basePath, pluginPath))
}

return require(pluginPath)
},
})
context.build = build
css = build(hasTailwind ? candidates : [])
Expand Down
11 changes: 9 additions & 2 deletions packages/@tailwindcss-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { IO, Parsing, scanFiles } from '@tailwindcss/oxide'
import { Features, transform } from 'lightningcss'
import path from 'path'
import { compile } from 'tailwindcss'
import { loadPlugin } from 'tailwindcss/io'
import type { Plugin, Rollup, Update, ViteDevServer } from 'vite'

export default function tailwindcss(): Plugin[] {
Expand Down Expand Up @@ -74,8 +73,16 @@ export default function tailwindcss(): Plugin[] {
}

function generateCss(css: string, inputPath: string) {
let basePath = path.dirname(path.resolve(inputPath))

return compile(css, {
loadPlugin: loadPlugin(inputPath),
loadPlugin: (pluginPath) => {
if (pluginPath[0] === '.') {
return require(path.resolve(basePath, pluginPath))
}

return require(pluginPath)
},
}).build(Array.from(candidates))
}

Expand Down
5 changes: 0 additions & 5 deletions packages/tailwindcss/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
"require": "./dist/lib.js",
"import": "./src/index.ts"
},
"./io": {
"types": "./src/io.ts",
"require": "./dist/io.js",
"import": "./src/io.ts"
},
"./package.json": "./package.json",
"./index.css": "./index.css",
"./index": "./index.css",
Expand Down
13 changes: 0 additions & 13 deletions packages/tailwindcss/src/io.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/tailwindcss/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ export default defineConfig({
dts: true,
entry: {
lib: 'src/index.ts',
io: 'src/io.ts',
},
})
Loading