webpack.config.js 1.6 KB

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