webpack.config.js 1.7 KB

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