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

Global CSS import does not handle backslashes correctly #209

Open
jsardev opened this issue Dec 26, 2023 · 2 comments · May be fixed by #210
Open

Global CSS import does not handle backslashes correctly #209

jsardev opened this issue Dec 26, 2023 · 2 comments · May be fixed by #210

Comments

@jsardev
Copy link

jsardev commented Dec 26, 2023

I wanted to use Tailwind CSS arbitrary values and it did not work correctly with current create-figma-plugin implementation.

The problem is that Tailwind outputs properly escaped [/] signs in css, but it is not handled correctly in the inline import logic.

Consider this output.css file

.grid-cols-\[1fr_1fr\] {
  grid-template-columns: 1fr 1fr;
}

After importing it via import '!./output.css' we get:

.grid-cols-[1fr_1fr] {
  grid-template-columns: 1fr 1fr;
}

Which is incorrect CSS - the [/] values are considered atrribute selectors and not strings.

Additional info

Version: 3.1.0

@jsardev jsardev linked a pull request Dec 26, 2023 that will close this issue
@arkus-pm
Copy link

As for some reason 210 is not merged for a month and 182 is not merged for 6 months, here's temporary fix for arbitary values in Tailwind:

❗️ replace tailwind in filter: /tailwind\.js$/ with the name of your tailwind output file, which you import in your tsx files.

/* build-figma-plugin.ui.js */

const { readFileSync } = require("fs")

function fixTailwindInjectionPlugin() {
  return {
    name: "fix-tailwind-injection-plugin",
    setup(build) {
      build.onLoad({ filter: /tailwind\.js$/ }, async (args) => {
        const contents = readFileSync(args.path, "utf8")

        const modifiedContents = contents
          .replaceAll("\\2c ", "\\\\,")
          .replaceAll("\\[", "\\\\[")
          .replaceAll("\\]", "\\\\]")

        return { contents: modifiedContents, loader: "js" }
      })
    },
  }
}

module.exports = function (buildOptions) {
  return {
    ...buildOptions,
    define: {
      global: "window",
    },
    plugins: [
      ...buildOptions.plugins
      fixTailwindInjectionPlugin(),
    ],
  }
}

@jsardev
Copy link
Author

jsardev commented Mar 31, 2024

@arkus-pm Thank you for the workaround! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants