Automatic generation: bundle.js and index.html
In the directory of the project:
npm the init -yes
npm install shock -D
npm install [email protected] -D
npm install css-loader -D; npm install style-loader -D
npm install http-webpack-plugin
npm install http-server
"Dev": "webpack" must be configured on, so as to use. npm run dev dev can easily change the name does not matter.
Here's exports this path: . Path Resolve ( './dist') , is a relative path absolute path absolute turn and then go to the back of the mosaic ./bundle.js file.
This index.html here is just a reference. Let html-webpack-plugin the reference taken to the next catalog generation dist index.html
npm install -g http-server this thing is used to do some tests. It should be noted that -g to download to go global.
Use: hs -o -p 9999 (9999 is the port number)
In generating webpack-dev-server environment, a widget
npm install webpack-dev-server -D
Directory structure, it generates the environment, and development environments separate:
package.json:
{ "name": "webpack_plugins", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "dev": "webpack-dev-server --open --hot --inline --config ./webpack.dev.config.js", // 开发环境
// --open 自动打开浏览器 --hot热更新 每当更新js css代码会自动在浏览器展示效果 "build": "webpack --config ./webpack.build.config.js" // 成产环境 }, "keywords": [], "author": "", "license": "ISC", "devDependencies": { "css-loader": "^2.1.1", "html-webpack-plugin": "^3.2.0", "install": "^0.12.2", "npm": "^6.9.0", "style-loader": "^0.23.1", "vue": "^2.6.10", "webpack-dev-server": "^3.4.1" // 这里也配置了 这个插件 }, "dependencies": { "webpack": "^3.12.0" } }
还是 执行 npm run dev