webpack.config.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. function getCurrentProjectname() {
  9. let pathSplit = __dirname.split(path.sep);
  10. return pathSplit[pathSplit.length - 1];
  11. }
  12. module.exports = {
  13. plugins: [
  14. new CleanWebpackPlugin(),
  15. new HtmlPlugin(
  16. {
  17. template: "./ui/frontend/errors_template.tpl",
  18. filename: path.resolve(__dirname, './ui/frontend/errors.tpl'),
  19. chunks: ["frontend"]
  20. }
  21. ),
  22. new HtmlPlugin(
  23. {
  24. template: "./ui/frontend/masterpage_template.tpl",
  25. filename: path.resolve(__dirname, './ui/frontend/masterpage.tpl'),
  26. chunks: ["frontend"]
  27. }
  28. ),
  29. new MiniCssExtractPlugin({filename: "styles.[contenthash].css"}),
  30. new webpack.ProvidePlugin({
  31. $: 'jquery',
  32. jQuery: 'jquery',
  33. "window.jQuery": 'jquery'
  34. })
  35. ],
  36. module: {
  37. rules: [
  38. {
  39. // For css...
  40. test: /\.(css|scss)$/,
  41. // ...use this loaders
  42. use: [
  43. MiniCssExtractPlugin.loader,
  44. "css-loader",
  45. "sass-loader"
  46. ]
  47. },
  48. // Import various assets
  49. {test: /\.(jpg|png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader?limit=100000'}
  50. ]
  51. },
  52. optimization: {
  53. minimizer: [
  54. new TerserJSPlugin(
  55. // Discard Comments
  56. {terserOptions: {output: {comments: false}}, parallel: 4}
  57. ),
  58. new OptimizeCSSAssetsPlugin(
  59. // Discard Comments
  60. {cssProcessorPluginOptions: {preset: ['default', {discardComments: {removeAll: true}}]}}
  61. )
  62. ],
  63. },
  64. entry: {
  65. "frontend": "./ui/frontend/js/frontend.js"
  66. },
  67. output: {
  68. publicPath: '/' + getCurrentProjectname() + '/assets/frontend/',
  69. path: path.resolve(__dirname, "assets/frontend/"),
  70. filename: "[name].[contenthash].js"
  71. },
  72. };