關於webpack的項目文件:https://gitee.com/codeFarmerPen/webpackjavascript
$ cnpm install html-webpack-plugin --save-dev
const path = require('path'); let htmlwebpackplugin = require('html-webpack-plugin');//引入html-webpack-plugin插件 let export_html= { entry: { main:__dirname+"/app/js/main.js",//入口文件 }, output: { path: __dirname+"/_build/", filename: "js/[name].js",//產出文件,name根據entry的入口文件鍵名定 }, module: { loaders: [ { test: /(\.jsx|\.js)$/, loader: 'babel-loader', query: { presets: ['es2015'] } }, ] } , plugins: [ //new一個模板出來 new htmlwebpackplugin({ template: './app/home.html',//入口文件 filename: 'home.html',//產出文件 }) ] }; module.exports=export_html;
app下的home.html,在_build下也生成了一個home.htmlcss
app/home.html:html
_build/home.html:java
能夠看到,生成的文件多了一個引入main.js的script;webpack
這是由於沒有對產出文件作限制的話,它會引入全部產出的JS文件。這個能夠在entry入口多引入一個js文件測試。git
webpack配置(第一步:配置前提):http://www.javashuo.com/article/p-zhierewo-eo.htmlweb
webpack配置(第二步:入門篇):http://www.javashuo.com/article/p-zgertkmc-mq.htmlnpm
webpack配置(第三步:ES6篇):http://www.javashuo.com/article/p-yornwkpw-dt.htmlbabel
webpack配置(第四步:html篇(基礎篇)):http://www.javashuo.com/article/p-ykguohhe-do.htmlapp
webpack配置(第四步:html篇(進階篇)):http://www.javashuo.com/article/p-nqgmvdah-hz.html
webpack配置(第四步:html篇(模板篇)):http://www.javashuo.com/article/p-cfrvmuzd-ea.html
webpack配置(第五步:less/css篇(基礎篇)):http://www.javashuo.com/article/p-ftegbnmw-p.html
webpack配置(第五步:less/css篇(進階篇)):http://www.javashuo.com/article/p-bkdzfetz-mx.html
webpack配置(第五步:less/css篇(url圖片篇)):http://www.javashuo.com/article/p-adtmrppc-mq.html