runoops.com

Webpack Uncaught SyntaxError

webpack打包umd,mode=“production”时,页面引用出错: Uncaught SyntaxError: Invalid or unexpected token

解决方法:

转换文件编码

1.当前项目中安装 webpack-encoding-plugin (不加 --save-dev)

npm install webpack-encoding-plugin
//或者 cnpm install webpack-encoding-plugin

2.webpack.config.js 文件中使用该插件

plugins: [

        ...
        new EncodingPlugin({ encoding: 'utf-8' }),
    ],

3.html 文件中设置字符集

<!doctype html>
<html>
<head>
      <meta charset="utf-8">
      <title>test</title>
      <script src="xxx.umd.js"></script>
</head>
<body>
...
</body>
</html>

Captcha Code

0 笔记

分享笔记

Inline Feedbacks
View all notes