Webpack && html-webpack-

2016-12-15  本文已影响110人  从此以后dapeng

安装 & 引用

npm i --save-dev html-webpack-plugin

// webpack.config.js
var HtmlWebpackPlugin = require('html-webpack-plugin');
...
plugins: [
    ...
    new HtmlWebpackPlugin({title: 'Webpack App' })
]

结果

命令行


Paste_Image.png

index.html


Paste_Image.png

Case1 添加 template

new HtmlWebpackPlugin({ 
      template: __dirname + "/app/index.tmpl.html"
    })

// index.tmpl.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Webpack Sample Project</title>
  </head>
  <body>
    <div id='root'>
    </div>
  </body>
</html>
Paste_Image.png

命令行

Paste_Image.png

打包后

Paste_Image.png
// index.html
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Webpack Sample Project</title>
  </head>
  <body>
    <div id='root'>
    </div>
  <script type="text/javascript" src="init.js"></script><script type="text/javascript" src="second.js"></script><script type="text/javascript" src="main.js"></script></body>
</html>

总结

Configuration

You can pass a hash of configuration options to HtmlWebpackPlugin. Allowed values are as follows:

Here's an example webpack config illustrating how to use these options:

{
  entry: 'index.js',
  output: {
    path: 'dist',
    filename: 'index_bundle.js'
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'My App',
      filename: 'assets/admin.html'
    })
  ]
}
上一篇 下一篇

猜你喜欢

热点阅读