G_lander

My epic webpack setup

Dec 19th, 2019
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const path = require("path")
  2. const HtmlWebpackPlugin = require("html-webpack-plugin")
  3. const MinifyPlugin = require("babel-minify-webpack-plugin")
  4. const ProgressPlugin = require("progress-webpack-plugin")
  5. const glob = require("glob")
  6. const prod = process.env.NODE_ENV === "production"
  7. let plugins = [
  8.     new HtmlWebpackPlugin({
  9.         template: "src/pages/index.html",
  10.         filename: "index.html",
  11.         inject: true
  12.     }),
  13.     new ProgressPlugin({ colors: true })
  14. ]
  15. if (prod)
  16.     plugins.push(new MinifyPlugin({}, { comments: false }))
  17. const entries = glob.sync("./src/scripts/**/*.js", {})
  18. module.exports = {
  19.     entry: entries,
  20.     output: {
  21.         filename: "main.js",
  22.         path: path.resolve(__dirname, "dist"),
  23.     },
  24.     mode: prod ? "production" : "development",
  25.     plugins: plugins,
  26.     module: {
  27.         rules: [
  28.             {
  29.                 test: /\.m?jsx?/,
  30.                 exclude: /node_modules/,
  31.                 use: ["eslint-loader", "babel-loader"]
  32.             },
  33.             {
  34.                 "test": /\.css/,
  35.                 use: {
  36.                     loader: "css-loader"
  37.                 }
  38.             },
  39.             {
  40.                 test: /\.(png|jpe?g|gif)$/i,
  41.                 use: [
  42.                     {
  43.                         loader: "file-loader",
  44.                     },
  45.                 ],
  46.             }
  47.         ]
  48.     },
  49.     resolve: {
  50.         extensions: [".jsx", ".js", ".json"]
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment