使用 babel 7.5.5、core-js 3.1.4 和 webpack 4.38.0,我如何從轉(zhuǎn)譯中排除 core-js?我不想node_modules完全排除,因為我有需要轉(zhuǎn)譯的庫如果我使用exclude: /node_modules\/(core-js)/,一個 core-js 模塊會拋出類型錯誤:$ 不是函數(shù)這讓我有另外兩個選擇。改用包含,包含我的 src 目錄和需要一一轉(zhuǎn)換的每個依賴項使用useBuiltIns: entry而不是使用,因為在這種情況下exclude: /node_modules/\(core-js)/有效,并且importcore.js 位于 main.js 的頂部這兩個選項對我來說似乎都不是很好的解決方案,因為usage自 7.4以來“不再是實驗性的”。有什么辦法可以使用用法讓它工作嗎?它是 babel-loader 還是 babel 中的錯誤?還是我的配置有問題?這是我的 Webpack 配置:const path = require('path');const webpack = require('webpack');module.exports = { mode: 'production', entry: { main: ['./src/main'], }, output: { path: path.resolve(__dirname, './build/'), publicPath: '/build/' }, module: { rules: [ { test: /\.js$/, exclude: /node_modules\/(core-js)/, use: { loader: 'babel-loader' }, }, { test: require.resolve('jquery'), use: [ { loader: 'expose-loader', options: 'jQuery' }, { loader: 'expose-loader', options: '$' } ] } ] }, plugins: [ new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery', 'window.jQuery': 'jquery' }) ],};這是我的 babel 配置:module.exports = function (api) { api.cache(true); return { presets: [ [ '@babel/preset-env', { corejs: { version: 3, }, useBuiltIns: 'usage', } ] ], };};您可以使用以下存儲庫重現(xiàn)錯誤:https : //github.com/tomm1996/usebuiltins-exclude-test
如何使用 useBuiltIns: "usage" 排除 core-js
料青山看我應(yīng)如是
2021-09-04 15:04:21