webpack.config.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. const path = require("path");
  2. const TerserJSPlugin = require('terser-webpack-plugin');
  3. const HtmlPlugin = require("html-webpack-plugin");
  4. //const HtmlPrefixPlugin = require("html-webpack-prefix-plugin");
  5. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  6. const CleanWebpackPlugin = require("clean-webpack-plugin");
  7. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  8. module.exports = {
  9. plugins: [
  10. new CleanWebpackPlugin(),
  11. new HtmlPlugin(
  12. {
  13. template: "./ui/masterpage_template.tpl",
  14. //prefix: 'ui/',
  15. filename: "../masterpage.tpl",
  16. //favicon: "../omlink/ui/images/favicon.ico"
  17. }
  18. ),
  19. //new HtmlPrefixPlugin(),
  20. new MiniCssExtractPlugin({filename: "styles.[contenthash].css"})
  21. ],
  22. module: {
  23. rules: [
  24. {
  25. // For css...
  26. test: /\.(css|scss)$/,
  27. // ...use this loaders
  28. use: [
  29. {loader: "style-loader"},
  30. MiniCssExtractPlugin.loader,
  31. {loader: "css-loader", options: {url: false,}},
  32. "sass-loader"
  33. ]
  34. }
  35. ]
  36. },
  37. optimization: {
  38. minimizer: [
  39. new TerserJSPlugin(
  40. // Discard Comments
  41. {terserOptions: {output: {comments: false}}, parallel: 4}
  42. ),
  43. new OptimizeCSSAssetsPlugin(
  44. // Discard Comments
  45. {cssProcessorPluginOptions: {preset: ['default', {discardComments: {removeAll: true}}],}}
  46. )
  47. ],
  48. },
  49. entry: "./ui/js/index.js",
  50. output: {
  51. publicPath: 'ui/dist/',
  52. path: path.resolve(__dirname, "ui/dist/"),
  53. filename: "bundle.[contenthash].js"
  54. },
  55. mode: "production"
  56. };