Commit 1843ff3b8c188224d525409f2572b343cb85a05c

Authored by Aresn
Committed by GitHub
2 parents 1f561319 5af94c52

Merge pull request #324 from huixisheng/2.0

add html-webpack-plugin
build/webpack.dev.config.js
... ... @@ -5,6 +5,7 @@
5 5 var path = require('path');
6 6 var webpack = require('webpack');
7 7 var ExtractTextPlugin = require('extract-text-webpack-plugin');
  8 +var HtmlWebpackPlugin = require('html-webpack-plugin');
8 9  
9 10 module.exports = {
10 11 // 入口
... ... @@ -15,7 +16,7 @@ module.exports = {
15 16 // 输出
16 17 output: {
17 18 path: path.join(__dirname, '../test/dist'),
18   - publicPath: '/test/dist/',
  19 + publicPath: '',
19 20 filename: '[name].js',
20 21 chunkFilename: '[name].chunk.js'
21 22 },
... ... @@ -99,8 +100,15 @@ module.exports = {
99 100 }
100 101 },
101 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 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 65 "gulp-less": "^3.1.0",
66 66 "gulp-rename": "^1.2.2",
67 67 "html-loader": "^0.3.0",
  68 + "html-webpack-plugin": "^2.28.0",
68 69 "less": "^2.7.1",
69 70 "less-loader": "^2.2.3",
70 71 "style-loader": "^0.13.1",
... ...
test/index.html
... ... @@ -3,11 +3,11 @@
3 3 <head>
4 4 <meta charset="UTF-8">
5 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 7 </head>
8 8 <body>
9 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 12 </body>
13 13 </html>
... ...