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