question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Feature]: Allow custom esbuild-Plugins through remix.config.js

See original GitHub issue

What is the new or updated feature that you are suggesting?

Allow us to add esbuild-Plugins through the remix.config.js so we can bundle our for Example CSS with PostCSS, SASS or more. I know it was already suggested in #192 and “declined” because the Team isn’t comfortable with locking into esbuild.

I understand that but would like to propose a different Idea for the time being: allow us to set a new Key like dangerouslySetEsbuildPlugins so we can add esbuild-Plugins.

Why should this feature be included?

So we can bundle our CSS in our Way without the need to setup another CLI Process (which isn’t Hard I agree but could be avoided with a single Key for us to use). And we could use the Folder Structure like it was intended and don’t have another styles-Folder in a different Location.

This would of course just be a temporary “fix” until a better Solution for processing CSS is found which will officially be supported by Remix. Since it’s named dangerouslySetEsbuildPlugins (or something else) it could be documented as just a Way for now and that it will be removed in a later Update.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:49
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

19reactions
jensengcommented, Jan 31, 2022

I found a way to do this, though the standard caveats apply (shameful hack, unsupported, subject to break in the future, etc., etc.) 😄 … If you create an esbuild-overrides.js like so:

const esbuild = require("esbuild");
const Module = require("module");

const originalRequire = Module.prototype.require;
const originalBuild = esbuild.build;

const build = (options) => {
  return originalBuild({
    ...options,
    // add in your overrides here, making sure to preserve original nested options., e.g.
    // plugins: [...options.plugins, myCustomPlugin],
  });
};

Module.prototype.require = function (id) {
  // when remix requires esbuild, it will get our modified build function from above
  if (id === "esbuild") {
    return { ...esbuild, build };
  }
  return originalRequire.apply(this, arguments);
};

Then change your build/dev scripts in package.json to load it before invoking remix:

"build": "NODE_OPTIONS='-r ./esbuild-overrides' remix build",
"dev": "NODE_OPTIONS='-r ./esbuild-overrides' remix watch",
11reactions
ionut-botizancommented, Dec 12, 2021

I’d also like to see support for esbuild plugins as that will (hopefully) allow us to use LinariaCSS in a Remix project. If you’re not familiar with it, Linaria is a zero-runtime CSS-in-JS library that compiles your styles into static CSS files at build time, offering a great mix of DX and runtime performance.

Some of its (cherry-picked) benefits are:

  • Scoped selectors
  • Automatic unused styles removal
  • Automatic vendor prefixing
  • Static CSS (doh) that can be loaded in parallel to JS
  • Works without JavaScript
  • Full power of CSS / No new syntax to learn (you just write CSS in a tagged template literal) with JS variables/expressions interpolation.

Basically, we get to write something like the following but still have all the benefits of serving plain CSS that needs no runtime JS:

// src/styling/theme.ts

export const theme = {
    colors: {
        primary: 'hotpink',
        // ...
    },
    spacing: { sm: 8, md: 12, lg: 24 }
    // ...
} as const
// src/pages/Home.styles.ts

import { css } from '@linaria/core'
import { lighten } from 'polished'
import { theme } from '../styling/theme'

export const button = css`
  background-color: ${theme.colors.primary};

  &:hover {
    background-color: ${lighten(0.2, theme.colors.primary})};
  }
`
Read more comments on GitHub >

github_iconTop Results From Across the Web

Plugins - esbuild
The plugin API allows you to inject code into various parts of the build process. ... An esbuild plugin is an object with...
Read more >
Build an esbuild plugin
Chance Strickland will teach us how to extend esbuild with custom plugins in this ... CHANCE: All the JavaScript you write in Remix...
Read more >
A library that makes it possible to change the configuration ...
What is this? ... This is a library that makes it possible to change the configuration values of the Remix compiler (esbuild). For...
Read more >
Create Infinite Scroll Images in Remix
This tutorial will walk us through implementing infinite scroll in an image gallery using the react-infinite-scroll-component with Remix.
Read more >
Twitter \ 🎄🧁 Mark Dalgleish (markdalgleish@)
I've wanted this feature in TypeScript for so long. ... side effect imports in. @remix_run. , mainly to support npm packages that import...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found