-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add support for the tailwindcss/plugin export
#14173
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
Changes from 12 commits
ab01a93
440cae3
de2c3f5
0ba2ef1
1fed940
a08432b
489b742
f94ceec
d722113
40dc22f
cec3d56
1f56962
94c4b0c
d88e63f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| // This file exists so that `plugin.ts` can be written one time but be compatible with both CJS and | ||
| // ESM. Without it we get a `.default` export when using `require` in CJS. | ||
|
|
||
| // @ts-ignore | ||
| module.exports = require('./plugin.ts').default | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There doesn't appear to be a way for tsup to compile a default export to |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import { test } from 'vitest' | ||
| import { compile } from '.' | ||
| import plugin from './plugin' | ||
|
|
||
| const css = String.raw | ||
|
|
||
| test('plugin', async ({ expect }) => { | ||
| let input = css` | ||
| @plugin "my-plugin"; | ||
| ` | ||
|
|
||
| let compiler = await compile(input, { | ||
| loadPlugin: async () => { | ||
| return plugin(function ({ addBase }) { | ||
| addBase({ | ||
| body: { | ||
| margin: '0', | ||
| }, | ||
| }) | ||
| }) | ||
| }, | ||
| }) | ||
|
|
||
| expect(compiler.build([])).toMatchInlineSnapshot(` | ||
| "@layer base { | ||
| body { | ||
| margin: 0; | ||
| } | ||
| } | ||
| " | ||
| `) | ||
| }) | ||
|
|
||
| test('plugin.withOptions', async ({ expect }) => { | ||
| let input = css` | ||
| @plugin "my-plugin"; | ||
| ` | ||
|
|
||
| let compiler = await compile(input, { | ||
| loadPlugin: async () => { | ||
| return plugin.withOptions(function (opts = { foo: '1px' }) { | ||
| return function ({ addBase }) { | ||
| addBase({ | ||
| body: { | ||
| margin: opts.foo, | ||
| }, | ||
| }) | ||
| } | ||
| }) | ||
| }, | ||
| }) | ||
|
|
||
| expect(compiler.build([])).toMatchInlineSnapshot(` | ||
| "@layer base { | ||
| body { | ||
| margin: 1px; | ||
| } | ||
| } | ||
| " | ||
| `) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import type { Config, PluginFn, PluginWithConfig, PluginWithOptions } from './plugin-api' | ||
|
|
||
| function createPlugin(handler: PluginFn, config?: Partial<Config>): PluginWithConfig { | ||
| return { | ||
| handler, | ||
| config, | ||
| } | ||
| } | ||
|
|
||
| createPlugin.withOptions = function <T>( | ||
| pluginFunction: (options?: T) => PluginFn, | ||
| configFunction: (options?: T) => Partial<Config> = () => ({}), | ||
| ): PluginWithOptions<T> { | ||
| function optionsFunction(options: T): PluginWithConfig { | ||
| return { | ||
| handler: pluginFunction(options), | ||
| config: configFunction(options), | ||
| } | ||
| } | ||
|
|
||
| optionsFunction.__isOptionsFunction = true as const | ||
|
|
||
| return optionsFunction as PluginWithOptions<T> | ||
| } | ||
|
|
||
| export default createPlugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this is better or not 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
inone is cleaner if TypeScript is happy with it.