Advertisement
G_lander

My config

Dec 24th, 2019
192
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 ESLintPlugin = require("eslint-webpack-plugin")
  7. const prod = process.env.NODE_ENV === "production"
  8. let plugins = [
  9.     new ProgressPlugin({ colors: true }),
  10.     new ESLintPlugin()
  11. ]
  12. if (prod)
  13.     plugins.push(new MinifyPlugin({}, { comments: false }))
  14. let jsGlobalEntries = []
  15. let jsEntries = {}
  16.  
  17. glob.sync("./src/scripts/**/index.js").forEach(element => {
  18.     const path = element.split("/")
  19.     const name = path[path.length - 2]
  20.  
  21.     jsEntries[name] = element
  22. })
  23. glob.sync("./src/scripts/*.js").forEach(element => {
  24.     const path = element.split("/")
  25.     const name = path[path.length - 1].split(".")[0]
  26.     jsGlobalEntries.push(name)
  27.     jsEntries[name] = element
  28. })
  29.  
  30. glob.sync("./src/pages/*.html", {}).forEach(element => {
  31.     const path = element.split("/")
  32.     const name = path[path.length - 1].split(".")[0]
  33.     plugins.push(new HtmlWebpackPlugin({
  34.         template: element,
  35.         filename: `${name}/index.html`,
  36.         inject: true,
  37.         chunks: [...jsGlobalEntries, name]
  38.     }))
  39. })
  40. module.exports = {
  41.     entry: jsEntries,
  42.     output: {
  43.         filename: "[name].js",
  44.         path: path.resolve(__dirname, "dist"),
  45.     },
  46.     mode: prod ? "production" : "development",
  47.     plugins: plugins,
  48.     module: {
  49.         rules: [
  50.             {
  51.                 test: /\.m?jsx?/,
  52.                 exclude: /node_modules/,
  53.                 use: ["babel-loader"]
  54.             },
  55.             {
  56.                 "test": /\.css/,
  57.                 include: /\.\/src\/\/styles/,
  58.                 use: {
  59.                     loader: "css-loader"
  60.                 }
  61.             },
  62.             {
  63.                 test: /\.(png|jpe?g|gif)$/i,
  64.                 use: [
  65.                     {
  66.                         loader: "file-loader",
  67.                     },
  68.                 ],
  69.             }
  70.         ]
  71.     },
  72.     resolve: {
  73.         extensions: [".jsx", ".js", ".json"]
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement