This commit is contained in:
Alex 2024-04-06 19:01:08 -04:00
parent 39851182ec
commit 8c789367af
4 changed files with 19 additions and 16 deletions

2
.gitignore vendored
View File

@ -130,3 +130,5 @@ dist
.yarn/build-state.yml .yarn/build-state.yml
.yarn/install-state.gz .yarn/install-state.gz
.pnp.* .pnp.*
repl.ts

View File

@ -1,6 +1,6 @@
{ {
"name": "@aet/babel-tailwind", "name": "@aet/babel-tailwind",
"version": "0.0.1-beta.3", "version": "0.0.1-beta.4",
"main": "dist/index.js", "main": "dist/index.js",
"license": "MIT", "license": "MIT",
"private": true, "private": true,

View File

@ -256,16 +256,20 @@ function babelTailwind(
*/ */
export const babelPlugin = ({ export const babelPlugin = ({
filter = /\.[jt]sx?$/, filter = /\.[jt]sx?$/,
getPlugins, plugins: getPlugins,
}: { }: {
filter?: RegExp; filter?: RegExp;
getPlugins(file: { path: string; contents: string }): babel.PluginItem[]; plugins:
| babel.PluginItem[]
| ((file: { path: string; contents: string }) => babel.PluginItem[]);
}): esbuild.Plugin => ({ }): esbuild.Plugin => ({
name: "babel-plugin", name: "babel-plugin",
setup(build) { setup(build) {
build.onLoad({ filter }, ({ path }) => { build.onLoad({ filter }, ({ path }) => {
const load = once(() => readFileSync(path, "utf-8")); const load = once(() => readFileSync(path, "utf-8"));
const plugins = getPlugins({ const plugins = Array.isArray(getPlugins)
? getPlugins
: getPlugins({
path, path,
get contents() { get contents() {
return load(); return load();
@ -278,7 +282,7 @@ export const babelPlugin = ({
const { code } = transformSync(load(), { const { code } = transformSync(load(), {
parserOpts: { parserOpts: {
plugins: ["jsx", "typescript"], plugins: ["jsx", "decorators", "typescript", "importAttributes"],
}, },
filename: path, filename: path,
plugins, plugins,
@ -339,7 +343,7 @@ const esbuildPlugin = (
build.onLoad({ filter: /.*/, namespace: ESBUILD_NAMESPACE }, async ({ path }) => { build.onLoad({ filter: /.*/, namespace: ESBUILD_NAMESPACE }, async ({ path }) => {
if (path === "directive:base") { if (path === "directive:base") {
return { return {
contents: (await compile(`@tailwind base;`)).css!, contents: (await compile(`@tailwind base;`)).css,
loader: "css", loader: "css",
}; };
} }

View File

@ -12,10 +12,7 @@ export default defineConfig({
define: { define: {
"process.env.BABEL_TAILWIND_BUILD": "true", "process.env.BABEL_TAILWIND_BUILD": "true",
}, },
esbuildOptions(options) { banner: {
options.banner = {
...options.banner,
js: "/* eslint-disable */", js: "/* eslint-disable */",
};
}, },
}); });