Theo's Typesafe CultTTC
Theo's Typesafe Cult2y ago
3 replies
BlueBeka

How to webpack? (in nextjs)

I can do what I want to do super easy in rollup but I can't for the life of me figure out how to do it in webpack.
Essentially all I want to do is run my source code through a tool to transform it before it's compiled.
My source code is in TypeScript but my tool only works with JavaScript, so I need to add the transformation after the the TypeScript transpilation.
I created a webpack loader that seem to work fine for js file, but I don't know how to get it to work for ts files too.

This is what I've got so far:
// next.config.js
export default {
  // ...

  webpack: (webpackConfig, { dev }) => {
    if (!dev) {
      webpackConfig.module.rules.push({
        test: /\.js/,
        exclude: /node_modules/,
        loader: fileURLToPath(import.meta.resolve("deassert/webpack-loader")),
      });
    }
    return webpackConfig;
  },
};


Is this something that can be done in webpack, hopefully somewhat easily?
Was this page helpful?