webpack.config.js 2.0 KB

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