【问题标题】:Eval Error with Webpack 4 + Babel 7 chunksWebpack 4 + Babel 7 块的 Eval 错误
【发布时间】:2019-08-06 21:40:12
【问题描述】:

Babel 7 + Webpack 4 块未在 Edge 中加载。在 Firefox、Chrome、Safari、Opera 中工作。

当我加载一个页面和我的入口 js 文件 (build.js) 时,edge 会尝试加载我认为是块的内容,但会加载如下内容。

https://www.myurl.com/mypage/eval%20code%20(36297)

控制台中没有错误。

我尝试更新我的 babel 配置以包含不同的预设/插件,并由 .browserslistrc 更新为“默认”,这在过去一直有效。

babel.config.js

module.exports = function (api) {
    api.cache(false);

    const presets = [
        [
            '@babel/preset-env',
            {
                "useBuiltIns": "entry",
                "corejs": 3,
            },
        ],
    ].filter(Boolean);

    const plugins = [
        "@babel/plugin-syntax-dynamic-import",
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-object-rest-spread",
        "@babel/plugin-transform-runtime",

    ].filter(Boolean);

    return {
        presets,
        plugins,
    };
};

.browserslistrc

defaults

webpack.config.js

module.exports = {
    stats: {
        children: true,
    },
    entry: [
        "core-js/modules/es.promise",
        "core-js/modules/es.array.iterator",
        './application/resources/js/app.js',
    ],
    output: {
        path: path.resolve(__dirname, './public'),
        publicPath: assets_path,
        filename: 'js/build.js',
        chunkFilename: 'js/chunk.[chunkhash].js',
    },
    performance: {
        hints: "warning",
    },
    optimization: {
        minimizer: [
            new OptimizeCSSAssetsPlugin(),
            new TerserPlugin({
                sourceMap: true,
            }),
        ],
    },
    plugins: getPlugins(),
    module: {
        rules: [
            {
                test: /\.vue$/,
                loader: 'vue-loader',
            },

            {
                test: /\.m?js$/,
                exclude: /(node_modules|bower_components)/,
                loader: 'babel-loader',
                include: [
                    path.resolve(__dirname, './application/'),
                    /vue2-datatable-component/,
                ],
            },
            {
                test: /\.css$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                ],
            },
            {
                test: /\.styl(us)?$/,
                loader: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    'stylus-loader',
                ],
            },
            {
                test: /\.s(c|a)ss$/,
                use: [
                    MiniCssExtractPlugin.loader,
                    'css-loader',
                    {
                        loader: 'sass-loader',
                        options: {
                            implementation: require('sass'),
                            fiber: require('fibers'),
                            indentedSyntax: true, // optional
                        },
                    },
                ],
            },
        ],
    },
}

【问题讨论】:

    标签: webpack microsoft-edge babeljs webpack-4


    【解决方案1】:

    您使用的是哪个版本的 Microsoft Edge 浏览器?基于this document,如果您需要使用transform-runtime 支持core-js,您现在将传递corejs 选项并使用@babel/runtime-corejs2 依赖而不是@babel/runtime。像这样:

    # install the runtime as a dependency
    npm install @babel/runtime-corejs2
    # install the plugin as a devDependency
    npm install @babel/plugin-transform-runtime --save-dev
    

    {
      "plugins": [
    -   ["@babel/plugin-transform-runtime"],
    +   ["@babel/plugin-transform-runtime", {
    +     "corejs": 2,
    +   }],
      ]
    }
    

    【讨论】:

    • 我使用的是 Edge 42.17134.1.0。 EdgeHTML 17.17134。以上没有奏效。我尝试了所有不同的配置,corejs2,corejs3。没运气。在 chrome、firefox、safari 和 opera 中工作的完全相同的配置在 edge 上存在这个问题。
    • 我按照这个示例在我的 Edge 上使用 webpack 和 babel 进行了测试:valentinog.com/blog/babel。它工作正常。您能否向我们发送一个迷你样本,以便我们了解如何提供帮助?
    猜你喜欢
    • 1970-01-01
    • 2019-10-30
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-20
    • 2020-11-15
    • 1970-01-01
    • 2019-06-29
    相关资源
    最近更新 更多