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

Support for babel plugins #43

Open
RanzQ opened this issue Nov 18, 2021 · 4 comments
Open

Support for babel plugins #43

RanzQ opened this issue Nov 18, 2021 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@RanzQ
Copy link

RanzQ commented Nov 18, 2021

Just a feature suggestion. Instead of dropping babel-loader, it can be used together with esbuild-loader:

// define esbuild-loader
const esbuildLoader = {
  // These could be used for the patched babel-loader
  // test: /\.(js|mjs|jsx|ts|tsx)$/,
  // include: [paths.appSrc, ...optionalIncludes],
  loader: require.resolve('esbuild-loader'),
  options: esbuildLoaderOptions
    ? esbuildLoaderOptions
    : {
        loader: useTypeScript ? 'tsx' : 'jsx',
        target: 'es2015',
      },
};

// modify babel loader
const babelLoaderPrev = getLoader(
  webpackConfig,
  loaderByName('babel-loader')
).match.loader;

const { loader, options } = babelLoaderPrev;

const babelLoader = { loader, options };

// Only keep styled-components plugin, drop the rest
options.presets = [];
options.plugins = ['babel-plugin-styled-components'];

const babelEsbuildLoader = babelLoaderPrev;

// Switch to .use
delete babelEsbuildLoader.loader;
delete babelEsbuildLoader.options;

babelEsbuildLoader.use = [babelLoader, esbuildLoader];

Not sure how the api should look like, just added my own configuration to include styled-components plugin. It seems to work fine after esbuild has done all the heavy work.

Inspiration: https://news.ycombinator.com/item?id=26977799

@burhanuday
Copy link

It probably would diminish the improvements that esbuild-loader provides (this is the webpack loader this project uses)
Read about it here - https://github.com/privatenumber/esbuild-loader#is-it-possible-to-use-babel-plugins

@RanzQ
Copy link
Author

RanzQ commented Dec 27, 2021

@burhanuday Well, we get most of the speed improvements since TS -> JS is handled by esbuild-loader. Also the minifier is replaced.

Running babel-loader for example with the styled plugin only is pretty light.

@pradel pradel added enhancement New feature or request help wanted Extra attention is needed labels Dec 27, 2021
@Rishi500
Copy link

@RanzQ can you share webpack config using esbuild-loader and babel plugins together without using babel loader ?

@RanzQ
Copy link
Author

RanzQ commented Oct 21, 2022

I never said I'm not using babel-loader. It's in the example above. I use esbuild-loader in chain with babel-loader. You cannot use babel plugins with esbuild. They are babel plugins, not esbuild plugins.

The idea was share the tasks. TS transpiling is done using esbuild and some additions (styled-components) with babel. Babel can read the output of esbuild so we can do some light things there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants