意外的令牌错误:标记处index.html中的语法错误; Webpack 4

时间:2018-06-26 20:02:30

标签: express webpack

运行npm build之后,它将在dist文件夹中创建index.html文件,但是它在</script>标记处显示语法错误。一切在本地都可以正常工作(即使出现此语法错误),但在生产中会显示此错误,并且无法部署到Heroku。

下面是代码:dist/index.html

我的package.json文件:

  {
  "name": "viovo",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "engines": {
    "node": "v10.5.0"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server --open --mode development",
    "build": "webpack --mode production"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/ChuSong327/VioVo.git"
  },
  "author": "Chu",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/ChuSong327/VioVo/issues"
  },
  "homepage": "https://github.com/ChuSong327/VioVo#readme",
  "devDependencies": {
    "babel-core": "^6.26.3",
    "babel-loader": "^7.1.4",
    "babel-preset-env": "^1.7.0",
    "babel-preset-react": "^6.24.1",
    "html-loader": "^0.5.5",
    "html-webpack-plugin": "^3.2.0",
    "webpack": "^4.12.1",
    "webpack-cli": "^3.0.8",
    "webpack-dev-server": "^3.1.4"
  },
  "dependencies": {
    "@material-ui/core": "^1.1.0",
    "@material-ui/icons": "^1.1.0",
    "axios": "^0.18.0",
    "express": "^4.16.3",
    "moment": "^2.22.2",
    "react": "^16.4.0",
    "react-dom": "^16.4.0",
    "react-moment": "^0.7.0"
  }
}

我的webpack.config.js文件:

const HtmlWebPackPlugin = require("html-webpack-plugin");
const htmlPlugin = new HtmlWebPackPlugin({
    template: "./src/index.html",
    filename: "./index.html"
});

module.exports = {
    module:{
        rules: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                use:{
                    loader: "babel-loader"
                }
            },
            {
                test: /\.html$/,
                use: {
                    loader: "html-loader"
                }
                
            }
        ],
    },
    plugins: [htmlPlugin]
};

0 个答案:

没有答案