webpack.config.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. const path = require("path");
  2. const TerserJSPlugin = require('terser-webpack-plugin');
  3. const HtmlPlugin = require("html-webpack-plugin");
  4. const MiniCssExtractPlugin = require("mini-css-extract-plugin");
  5. const CleanWebpackPlugin = require("clean-webpack-plugin");
  6. const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
  7. const webpack = require("webpack");
  8. module.exports = {
  9. plugins: [
  10. new CleanWebpackPlugin(),
  11. new HtmlPlugin(
  12. {
  13. template: "./ui/masterpage_template.tpl",
  14. filename: "../masterpage.tpl",
  15. }
  16. ),
  17. new MiniCssExtractPlugin({filename: "styles.[contenthash].css"}),
  18. new webpack.ProvidePlugin({
  19. $: 'jquery',
  20. jQuery: 'jquery'
  21. })
  22. ],
  23. module: {
  24. rules: [
  25. {
  26. // For css...
  27. test: /\.(css|scss)$/,
  28. // ...use this loaders
  29. use: [
  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. };