From 5af94c529593a98385444df108e84ad3df801345 Mon Sep 17 00:00:00 2001 From: huixisheng Date: Wed, 1 Mar 2017 13:56:01 +0800 Subject: [PATCH] add HtmlWebpackPlugin --- build/webpack.dev.config.js | 14 +++++++++++--- package.json | 1 + test/index.html | 6 +++--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/build/webpack.dev.config.js b/build/webpack.dev.config.js index c3ba644e..ff61ffe5 100644 --- a/build/webpack.dev.config.js +++ b/build/webpack.dev.config.js @@ -5,6 +5,7 @@ var path = require('path'); var webpack = require('webpack'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); +var HtmlWebpackPlugin = require('html-webpack-plugin'); module.exports = { // 入口 @@ -15,7 +16,7 @@ module.exports = { // 输出 output: { path: path.join(__dirname, '../test/dist'), - publicPath: '/test/dist/', + publicPath: '', filename: '[name].js', chunkFilename: '[name].chunk.js' }, @@ -99,8 +100,15 @@ module.exports = { } }, plugins: [ - new ExtractTextPlugin({ filename: '[name].css', disable: false, allChunks: true }), // 提取CSS + // new ExtractTextPlugin({ filename: '[name].css', disable: false, allChunks: true }), + // new ExtractTextPlugin("[name].css",{ allChunks : true,resolve : ['modules'] }), // 提取CSS // https://doc.webpack-china.org/plugins/commons-chunk-plugin/ - new webpack.optimize.CommonsChunkPlugin({ name: 'vendors', filename: 'vendor.js' }) + new webpack.optimize.CommonsChunkPlugin({ name: 'vendors', filename: 'vendor.bundle.js' }), + new HtmlWebpackPlugin({ + inject: true, + filename: path.join(__dirname, '../test/dist/index.html'), + template: path.join(__dirname, '../test/index.html') // 模版文件 + }) + // new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'), // 提取第三方库 ] }; diff --git a/package.json b/package.json index 3a414e69..19f661ed 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "gulp-less": "^3.1.0", "gulp-rename": "^1.2.2", "html-loader": "^0.3.0", + "html-webpack-plugin": "^2.28.0", "less": "^2.7.1", "less-loader": "^2.2.3", "style-loader": "^0.13.1", diff --git a/test/index.html b/test/index.html index ea673357..e84e1c10 100644 --- a/test/index.html +++ b/test/index.html @@ -3,11 +3,11 @@ iView test page - +
- - +