Guest User

Untitled

a guest
Dec 10th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. const path = require("path");
  2. const HtmlWebpackPlugin = require("html-webpack-plugin");
  3. const TerserPlugin = require("terser-webpack-plugin");
  4. const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
  5. .BundleAnalyzerPlugin;
  6.  
  7. const getPlugins = env =>
  8. [
  9. new HtmlWebpackPlugin({
  10. filename: "index.html",
  11. template: path.join(__dirname, "public/index.html"),
  12. inject: true,
  13. chunks: ["app", "vendors"]
  14. }),
  15. env.analyze && new BundleAnalyzerPlugin()
  16. ].filter(plugin => plugin);
  17.  
  18. module.exports = env => {
  19. const config = {
  20. mode:
  21. env.NODE_ENV.development === "development" ? "development" : "production",
  22. entry: {
  23. app: [path.resolve(__dirname, "./src/index.js")],
  24. vendors: ["react", "react-dom"]
  25. },
  26. output: {
  27. path: path.join(__dirname, ".", "myDistribution", "ui"),
  28. filename: "js/[name]".concat(".[chunkhash:8].js")
  29. },
  30. resolve: {
  31. alias: {
  32. view: path.resolve(__dirname, "./src/View"),
  33. container: path.resolve(__dirname, "./src/Container")
  34. },
  35. extensions: [".js"],
  36. modules: [
  37. path.resolve(__dirname, "./src"),
  38. path.resolve(__dirname, "./node_modules")
  39. ]
  40. },
  41. devServer: {
  42. contentBase: path.join(__dirname, "public"),
  43. compress: true,
  44. port: 9000
  45. },
  46. plugins: getPlugins(env),
  47. module: {
  48. rules: [
  49. {
  50. test: /\.(js)$/,
  51. exclude: /node_modules/,
  52. use: ["cache-loader", "babel-loader?cacheDirectory", "thread-loader"]
  53. }
  54. ]
  55. },
  56. optimization: {
  57. splitChunks: {
  58. cacheGroups: {
  59. vendors: {
  60. test: /[\\/]node_modules[\\/]/,
  61. name: "vendors",
  62. chunks: "all"
  63. }
  64. }
  65. },
  66. minimizer: [
  67. new TerserPlugin({
  68. cache: true,
  69. parallel: true,
  70. terserOptions: {
  71. compress: {
  72. dead_code: true,
  73. conditionals: true,
  74. booleans: true
  75. },
  76. module: false,
  77. output: {
  78. comments: false,
  79. beautify: false
  80. }
  81. }
  82. })
  83. ]
  84. }
  85. };
  86. return config;
  87. };
Add Comment
Please, Sign In to add comment