目录
//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"
}
}