I change to the esbuild-loader but webpack cache doesn't seem to work

4
closed
lanmch
lanmch
Posted 8 months ago

I change to the esbuild-loader but webpack cache doesn't seem to work #208

Bug description

Before I use esbuild-loader, webpack cache with the babel-loader is working. But when I change to use the esbuild, it doesn't work. And here is my config about esbuild.

  {
    test: /\.jsx?$/,
    exclude: /node_modules/,
    oneOf: [
      {
        test: filePath => {
          if (!filePath) {
            return false;
          }
          try {
            const fileContent = fs.readFileSync(filePath).toString();
            return !hasDecorator(fileContent);
          } catch (e) {
            return false;
          }
        },
        use: [
          {
            loader: 'esbuild-loader',
            options: {
              loader: 'jsx',
              target: 'es2015',
            },
          },
        ],
      },
      // esbuild-loader is not support the decorators, so I try to use babel to compile these file
      {
        use: [
          {
            loader: 'babel-loader',
            options: {
              presets: ['@babel/preset-env', '@babel/preset-react'],
              plugins: [
                '@babel/plugin-transform-runtime',
                ['@babel/plugin-proposal-decorators', { 'legacy': true }],
                ['@babel/plugin-proposal-optional-chaining', { 'loose': false }],
                ['@babel/plugin-proposal-class-properties', { 'loose': true }],
                ['@babel/plugin-proposal-private-methods', { 'loose': true }],
                ['@babel/plugin-proposal-private-property-in-object', { 'loose': true }],
              ],
            },
          },
        ],
      },
    ],

  },
  {
    test: /\.tsx?$/,
    loader: 'esbuild-loader',
    options: {
      loader: 'tsx',
      target: 'es2015',
      tsconfigRaw: require('../../tsconfig.json'),
    },
  },

But the webpack log seems to have cache the file, but when i try to build the project the second time with no change about webpack, it doesn't hit the cache

I‘m expecting a reply!😄

Reproduction

Hope for a solution.

Node.js package manager

yarn

Environment

MacOS 11.4
node 14.16
npm 6.14.11
webpack 5.51.1

Can you contribute a fix?

  • I’m interested in opening a pull request for this issue.
privatenumber
privatenumber
Created 7 months ago

Thanks for the issue.

I'm not sure if I understand the issue though. Can you provide a minimal reproduction repo of the problem?

privatenumber
privatenumber
Created 6 months ago

Closing until reproduction is provided.

dons20
dons20
Created 5 months ago

I think OP was referring to this feature of babel-loader exposed in the options. However there's nothing in the config above that refers to caching. Perhaps OP expected the cache to work exactly like babel-loader

...
loader: require.resolve('babel-loader'),
options: {
  ...
  // This is a feature of `babel-loader` for webpack (not Babel itself).
  // It enables caching results in ./node_modules/.cache/babel-loader/
  // directory for faster rebuilds.
  cacheDirectory: true,
  cacheCompression: false,
  compact: false,
}