美文网首页
启动服务+热重载入+生成html

启动服务+热重载入+生成html

作者: huanghaodong | 来源:发表于2020-09-23 16:44 被阅读0次

目录


image.png
//webpack.config.js
var {CleanWebpackPlugin} = require('clean-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
var Webpack = require('webpack');
var path = require('path');
module.exports = {
  entry:{
    index:'./js/index.js'
  },
  output:{
    path: path.resolve(__dirname, 'dist'),
    filename:'bundle.js'
  },
  plugins:[
    new CleanWebpackPlugin(),
    new HtmlWebpackPlugin({
      template:'./index.html'
    }),
    //new Webpack.HotModuleReplacementPlugin() devServer.hot为true时可省略 内部自动执行 https://www.webpackjs.com/configuration/dev-server/#devserver-hot
  ],
  devServer:{
    port:'9091',
    contentBase: path.resolve(__dirname, 'dist'),
    hot:true
  },
  mode:'development'
}

//package.json
{
  "name": "test-threejs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "build": "webpack",
    "server": "webpack-dev-server --line"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "webpack": "^4.44.2",
    "webpack-cli": "^3.3.12"
  },
  "dependencies": {
    "clean-webpack-plugin": "^3.0.0",
    "html-webpack-plugin": "^4.5.0",
    "three": "^0.120.1",
    "webpack-dev-server": "^3.11.0"
  }
}


相关文章

网友评论

      本文标题:启动服务+热重载入+生成html

      本文链接:https://www.haomeiwen.com/subject/uveoyktx.html