Skip to content

Instantly share code, notes, and snippets.

@mattn9x
Created September 10, 2017 17:40
Show Gist options
  • Save mattn9x/f7709046b0069e8f9569cf4acf28d488 to your computer and use it in GitHub Desktop.
Save mattn9x/f7709046b0069e8f9569cf4acf28d488 to your computer and use it in GitHub Desktop.
custom plugin webpack
new HtmlWebpackPlugin({
  template: path.resolve(root, 'src/index.html'),
  hash: true, //them thẻ <script> với đường link đính kèm 1 mã hash
  cache: true, //cache file nếu có ko co thay đổi thì ko bundle lại
  showErrors: false, //neu co loi sẽ ghi vào file html
  minify: false, //false: ko minify html ngước lại tru: minify html
  filename: 'index.html',
  favicon: 'src/favicon.ico', //them file favicon vào trang html
  /*nạp các nhánh javascript bundle vào file html*/
  chunks: ['app', 'publicJS/ex-common', 'publicJS/ex2', 'publicJS/ex1', 'app-home'],
  chunksSortMode: function (a, b) {
    return (a.names[0] > b.names[0]) ? 1 : -1;
  }, //sắp xếp lại các file script chèn vào theo đúng thứ tự
  inject: 'body' //có 2 gia trị là body và head (chèn mã script vào nơi tương ứng)
})
// Plugin optimize cho code js
new webpack.optimize.UglifyJsPlugin({
  minimize: true,
  comments: false, //false: hủy toàn bộ comment khi bundle
  compress: {
    warnings: false,  //thông báo lỗi khi nén
    drop_console: true, //hủy hết console.log khi bundle
    unsafe: true
  }
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment