Commit 1843ff3b8c188224d525409f2572b343cb85a05c
Committed by
GitHub
Merge pull request #324 from huixisheng/2.0
add html-webpack-plugin
Showing
3 changed files
with
15 additions
and
6 deletions
Show diff stats
build/webpack.dev.config.js
| @@ -5,6 +5,7 @@ | @@ -5,6 +5,7 @@ | ||
| 5 | var path = require('path'); | 5 | var path = require('path'); |
| 6 | var webpack = require('webpack'); | 6 | var webpack = require('webpack'); |
| 7 | var ExtractTextPlugin = require('extract-text-webpack-plugin'); | 7 | var ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 8 | +var HtmlWebpackPlugin = require('html-webpack-plugin'); | ||
| 8 | 9 | ||
| 9 | module.exports = { | 10 | module.exports = { |
| 10 | // 入口 | 11 | // 入口 |
| @@ -15,7 +16,7 @@ module.exports = { | @@ -15,7 +16,7 @@ module.exports = { | ||
| 15 | // 输出 | 16 | // 输出 |
| 16 | output: { | 17 | output: { |
| 17 | path: path.join(__dirname, '../test/dist'), | 18 | path: path.join(__dirname, '../test/dist'), |
| 18 | - publicPath: '/test/dist/', | 19 | + publicPath: '', |
| 19 | filename: '[name].js', | 20 | filename: '[name].js', |
| 20 | chunkFilename: '[name].chunk.js' | 21 | chunkFilename: '[name].chunk.js' |
| 21 | }, | 22 | }, |
| @@ -99,8 +100,15 @@ module.exports = { | @@ -99,8 +100,15 @@ module.exports = { | ||
| 99 | } | 100 | } |
| 100 | }, | 101 | }, |
| 101 | plugins: [ | 102 | plugins: [ |
| 102 | - new ExtractTextPlugin({ filename: '[name].css', disable: false, allChunks: true }), // 提取CSS | 103 | + // new ExtractTextPlugin({ filename: '[name].css', disable: false, allChunks: true }), |
| 104 | + // new ExtractTextPlugin("[name].css",{ allChunks : true,resolve : ['modules'] }), // 提取CSS | ||
| 103 | // https://doc.webpack-china.org/plugins/commons-chunk-plugin/ | 105 | // https://doc.webpack-china.org/plugins/commons-chunk-plugin/ |
| 104 | - new webpack.optimize.CommonsChunkPlugin({ name: 'vendors', filename: 'vendor.js' }) | 106 | + new webpack.optimize.CommonsChunkPlugin({ name: 'vendors', filename: 'vendor.bundle.js' }), |
| 107 | + new HtmlWebpackPlugin({ | ||
| 108 | + inject: true, | ||
| 109 | + filename: path.join(__dirname, '../test/dist/index.html'), | ||
| 110 | + template: path.join(__dirname, '../test/index.html') // 模版文件 | ||
| 111 | + }) | ||
| 112 | + // new webpack.optimize.CommonsChunkPlugin('vendors', 'vendors.js'), // 提取第三方库 | ||
| 105 | ] | 113 | ] |
| 106 | }; | 114 | }; |
package.json
| @@ -65,6 +65,7 @@ | @@ -65,6 +65,7 @@ | ||
| 65 | "gulp-less": "^3.1.0", | 65 | "gulp-less": "^3.1.0", |
| 66 | "gulp-rename": "^1.2.2", | 66 | "gulp-rename": "^1.2.2", |
| 67 | "html-loader": "^0.3.0", | 67 | "html-loader": "^0.3.0", |
| 68 | + "html-webpack-plugin": "^2.28.0", | ||
| 68 | "less": "^2.7.1", | 69 | "less": "^2.7.1", |
| 69 | "less-loader": "^2.2.3", | 70 | "less-loader": "^2.2.3", |
| 70 | "style-loader": "^0.13.1", | 71 | "style-loader": "^0.13.1", |
test/index.html
| @@ -3,11 +3,11 @@ | @@ -3,11 +3,11 @@ | ||
| 3 | <head> | 3 | <head> |
| 4 | <meta charset="UTF-8"> | 4 | <meta charset="UTF-8"> |
| 5 | <title>iView test page</title> | 5 | <title>iView test page</title> |
| 6 | - <link href="/test/dist/main.css" rel="stylesheet"> | 6 | + <!-- <link href="/test/dist/main.css" rel="stylesheet"> --> |
| 7 | </head> | 7 | </head> |
| 8 | <body> | 8 | <body> |
| 9 | <div id="app"></div> | 9 | <div id="app"></div> |
| 10 | - <script type="text/javascript" src="/test/dist/vendors.js"></script> | ||
| 11 | - <script type="text/javascript" src="/test/dist/main.js"></script> | 10 | + <!-- <script type="text/javascript" src="/test/dist/vendor.js"></script> |
| 11 | + <script type="text/javascript" src="/test/dist/main.js"></script> --> | ||
| 12 | </body> | 12 | </body> |
| 13 | </html> | 13 | </html> |