Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const path = require("path")
- const HtmlWebpackPlugin = require("html-webpack-plugin")
- const MinifyPlugin = require("babel-minify-webpack-plugin")
- const ProgressPlugin = require("progress-webpack-plugin")
- const glob = require("glob")
- const ESLintPlugin = require("eslint-webpack-plugin")
- const prod = process.env.NODE_ENV === "production"
- let plugins = [
- new ProgressPlugin({ colors: true }),
- new ESLintPlugin()
- ]
- if (prod)
- plugins.push(new MinifyPlugin({}, { comments: false }))
- let jsGlobalEntries = []
- let jsEntries = {}
- glob.sync("./src/scripts/**/index.js").forEach(element => {
- const path = element.split("/")
- const name = path[path.length - 2]
- jsEntries[name] = element
- })
- glob.sync("./src/scripts/*.js").forEach(element => {
- const path = element.split("/")
- const name = path[path.length - 1].split(".")[0]
- jsGlobalEntries.push(name)
- jsEntries[name] = element
- })
- glob.sync("./src/pages/*.html", {}).forEach(element => {
- const path = element.split("/")
- const name = path[path.length - 1].split(".")[0]
- plugins.push(new HtmlWebpackPlugin({
- template: element,
- filename: `${name}/index.html`,
- inject: true,
- chunks: [...jsGlobalEntries, name]
- }))
- })
- module.exports = {
- entry: jsEntries,
- output: {
- filename: "[name].js",
- path: path.resolve(__dirname, "dist"),
- },
- mode: prod ? "production" : "development",
- plugins: plugins,
- module: {
- rules: [
- {
- test: /\.m?jsx?/,
- exclude: /node_modules/,
- use: ["babel-loader"]
- },
- {
- "test": /\.css/,
- include: /\.\/src\/\/styles/,
- use: {
- loader: "css-loader"
- }
- },
- {
- test: /\.(png|jpe?g|gif)$/i,
- use: [
- {
- loader: "file-loader",
- },
- ],
- }
- ]
- },
- resolve: {
- extensions: [".jsx", ".js", ".json"]
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement