webpack html-webpack-plugin 语法报错 es\html-webpack-plugin\default_index.ejs: Unexpected token (1:0)

先看问题
在这里插入图片描述

随着排除插件依赖 发现是html-webpack-plugin 和 babel-loader 冲突了
报错提示

Module build failed (from ./node_modules/babel-loader/lib/index.js):

es\html-webpack-plugin\default_index.ejs: Unexpected token (1:0)

所以需要在项目在构建时忽略掉依赖包,如下,babel-loader配置下加上exclude: /node_modules/配置,就是忽略依赖包的意思。
上代码

        {
    
    
                test: /.js$/,
                exclude: /node_modules/,
                use: {
    
    
                    loader: 'babel-loader',
                    options: {
    
    
                        presets: ['@babel/preset-env']
                    }
                }
            },

重新打包
在这里插入图片描述
成功解决上述问题

猜你喜欢

转载自blog.csdn.net/qq_45284938/article/details/128440245