簡體   English   中英

如何使用babel-loader將node_module內部的一個特定文件/文件夾從es6轉換為es5?

[英]How to transpile one particular file / folder inside node_module from es6 to es5 using babel-loader?

1.IE11在代碼中不支持ES6語法。 如果遇到任何ES6語法,它將引發錯誤。
2.我們在“ node_module / types.js / types.min.js”文件中使用了ES6語法,並且在webpack.config.js中排除了node_module。因此,由於babel-loader不會編譯types.min,它在IE11中的拋出錯誤.js從es6到es5。

我只想包含\\ node_modules \\ types.js以便在webpack.config.js文件中進行轉譯。 或任何更好的解決方案???

嘗試過

exclude: /node_modules\\/(?!(types.js)\\/).*/

但它包括整個node_module。

webpack.config.js

module: {
    rules: [
      {
        test: /\.jsx?$/,        
        // exclude: /node_modules/,
        exclude: /node_modules\/(?!(types.js)\/).*/,
        loader: 'babel-loader',
        query: {
          presets: ['es2015', 'react']
        }
      },
      {
        test: require.resolve('jquery'),
        use: ['expose-loader?jQuery', 'expose-loader?$']
      }
    ]
  },
exclude: /node_modules(?!(\/|\\)types.js)/,

在這里, types.js是您要包含的模塊名稱。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM