简体   繁体   中英

babel-loader not transpiling package in node_modules

I have already updated babel-loader and babel/core to newest.

"babel-loader": "8.2.2",
"@babel/core": "7.14.3",

It says that this is related to.babelrc, should use babel.config.js, not.babelrc, according to this question .

I have also updated the config, but still no luck.

react-spring,@react-spring,rafz should be transpired, but they don't.

exports.loadJavaScript = () => {
  return {
  module: {
    rules: [
      {
        test: [/\.jsx?$/, /\.js$/],
        include: [resolve('../src')],
        exclude: /node_modules(?!\/(react-spring|@react-spring|rafz))/,
        use: [
          {
            loader: 'thread-loader',
            options: jsWorkerPool,
          },
          {
            loader: 'babel-loader',
            options: {
              babelrc: false,
              cacheDirectory: true,
              configFile: path.resolve(
                __dirname,
                '../babel.config.js',
              ),
            }
          },
        ],
      },
    ],
  },
}};
module.exports = api => {
  const isDevelopment = process.env.NODE_ENV !== 'production';
  const enableRefresh = process.env.NOREFRESH !== 'true';

  api.cache.using(() => process.env.NODE_ENV);
  return {
    presets: [
      [
        '@babel/preset-env',
        {
          useBuiltIns: 'entry',
          corejs: { version: 3, proposals: true },
          targets: {
            browsers: ['last 2 versions', 'safari >= 7', 'ie >= 11'],
          },
        },
      ],
      '@babel/preset-react',
    ],
    plugins: [
      [
        '@babel/plugin-proposal-decorators',
        {
          legacy: true,
        },
      ],
      [
        '@babel/plugin-proposal-class-properties',
        {
          loose: true,
        },
      ],

      '@babel/plugin-proposal-nullish-coalescing-operator',
      '@babel/plugin-proposal-optional-chaining',
      '@babel/plugin-syntax-dynamic-import',
      isDevelopment && enableRefresh && require.resolve('react-refresh/babel'),
    ].filter(Boolean),
  };
};

anyone can help?

It's not related to the babel, but the babel-loader, I make the wrong config with both include and exclude, remove the following line, it works.

  -    include: [resolve('../src')],

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM