Polymer 3 + webpack + babel Class 没有 'new' 就无法调用构造函数 PolymerElement

Polymer 3 + webpack + babel Class constructor PolymerElement cannot be invoked without 'new'

我正在尝试扩展聚合物中的 mixin class。它工作正常但是当我尝试用 babel 转换我的代码时,我得到 Class constructor PolymerElement cannot be invoked without 'new.我一调用 super 就收到错误。我确定问题与使用转译的 class 代码扩展本机 class 有关,但我还找不到能够解决我的问题的 resource/example。我的猜测是我需要以不同方式配置我的 babel,但正如我所说,找到的示例没有帮助。 您可以在此处访问我重现错误的存储库:https://github.com/skukan159/DebuggingPolymerWebpack

这是我的 webpack 配置:

const webpack = require('webpack');
const path = require('path');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const WorkboxPlugin = require('workbox-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');


const webcomponentsjs = './node_modules/@webcomponents/webcomponentsjs';

const polyfills = [
    {
        from: path.resolve(`${webcomponentsjs}/webcomponents-*.{js,map}`),
        to: path.join(__dirname, 'wwwroot'),
        flatten: true
    },
    {
        from: './node_modules/web-animations-js/*{.js,.js.map}',
        to: './node_modules/web-animations-js/[name].[ext]'
    }
];
const assets = [
    {
        from: 'manifest.json',
        to: path.resolve(__dirname, 'wwwroot'),
        context: './src/'
    },
    {
        from: 'sw-service-worker.js',
        to: path.resolve(__dirname, 'wwwroot'),
        context: './src/'
    },
    {
        from: 'include/images/*',
        to: path.resolve(__dirname, 'wwwroot'),
        context: './src/'
    },
    {
        from: '*.html',
        to: path.resolve(__dirname, 'wwwroot'),
        context: './src/'
    }
];

module.exports = function (env) {
    return {
        entry: './src/index.js',
        output: {
            publicPath: '/',
            path: path.resolve(__dirname, 'wwwroot'), changed
            filename: "[name].[contenthash].js",  
            chunkFilename: '[name].[contenthash].js',
        },
        node: {
            dns: 'mock',
            net: 'mock'
        },
        optimization: {
            splitChunks: {
                cacheGroups: {
                    vendor: {
                       test: /[\/]node_modules[\/]/,
                       name: 'vendors',
                       chunks: 'all'
                    }
                }
            },
            runtimeChunk: 'single',
        },

        module: {
            rules: [
                {
                    test: /\.js$/,
                   exclude: /node_modules/,
                    use: {
                        loader: 'babel-loader',
                        options: {
                            presets: ['@babel/preset-env', { exclude: ["transform-classes"] }],
                            plugins: [
                                "@babel/plugin-proposal-class-properties",
                                "@babel/plugin-proposal-object-rest-spread",
                                "@babel/plugin-syntax-dynamic-import"
                            ]
                        }
                    }
                },

                {
                    "test": /\.html$/,
                    "use": [{
                        loader: 'html-loader',
                    }]
                },
                {
                    test: /\.json$/,
                    use: 'json-loader'
                },
                {
                    test: /\.(png|svg|jpg|gif)$/,
                    use: [
                        {
                            loader: 'file-loader',
                            options: {
                                name: '/img/[name].[ext]'
                            }
                        }
                    ]
                }
            ]
        },

        resolve: {
            modules: [
                "node_modules",
                path.resolve(__dirname, "src")
            ],
            extensions: [".js", ".json"],

            alias: {
                'markjs': path.resolve(__dirname, "./node_modules/mark.js/dist/mark.min.js"),
            }
        },

        plugins: [
            new webpack.HashedModuleIdsPlugin(),
            new HtmlWebpackPlugin({
                template: 'src/index.html'}),
            new webpack.ProvidePlugin({
                IntlMessageFormat: ['intl-messageformat/index.js', 'default'],
                'Mark': 'markjs'
            }),
            new CleanWebpackPlugin(['wwwroot']),
            new WorkboxPlugin.GenerateSW({
                swDest: 'sw.js',
                clientsClaim: true,
                skipWaiting: true
            }),
            new CopyWebpackPlugin([...polyfills, ...assets,
                {
                    from: 'include/components/oidc-client/oidc-client.min.js',
                    to: path.resolve(__dirname, 'wwwroot'),
                    context: './src/'
                },
            ]),
        ],

        watch: true,
        watchOptions: {
            aggregateTimeout: 1000,
            poll: true,
            poll: 500,
        },
    }
};

这是我的 .babelrc 文件

    {
  "presets": [
    [
      "@babel/preset-env",
      {
        "targets": {
          "browsers": [ "last 2 versions", "ie >= 11" ]
        },
        "exclude": [ "transform-classes" ]
      }
    ]
  ],
  "plugins": [
    "@babel/plugin-proposal-class-properties",
    "@babel/plugin-proposal-object-rest-spread",
    "@babel/plugin-syntax-dynamic-import"
  ]
}

我发现了问题所在。我需要从 webpack 配置文件中注释掉我的 babel 加载器的选项。只有这样才能应用我的 .babelrc 配置文件。