Created
May 12, 2020 14:29
-
-
Save lokesh1729/8b59cbe3673acaab78a3638556bf3f9d to your computer and use it in GitHub Desktop.
yahoooo!!! my first webpack config working fine :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require("path"); | |
const webpack = require("webpack"); | |
const TerserPlugin = require("terser-webpack-plugin"); | |
const { CleanWebpackPlugin } = require("clean-webpack-plugin"); | |
const HtmlWebpackPlugin = require("html-webpack-plugin"); | |
const MiniCssExtractPlugin = require("mini-css-extract-plugin"); | |
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin"); | |
module.exports = ({ mode, presets } = { mode: "production", presets: [] }) => ({ | |
devtool: "eval-cheap-module-source-map", | |
devServer: { contentBase: "./dist" }, | |
context: path.resolve(__dirname, "src"), | |
entry: { | |
main: "./main.js", | |
}, | |
mode: mode, | |
optimization: { | |
minimize: true, | |
minimizer: [new TerserPlugin()], | |
}, | |
output: { | |
filename: "[name].bundle.js", | |
path: path.resolve(__dirname, "dist"), | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.scss|\.css/, | |
use: [ | |
"style-loader", | |
MiniCssExtractPlugin.loader, | |
"css-loader", | |
"sass-loader", | |
], | |
}, | |
{ | |
test: /\.js/, | |
use: ["babel-loader"], | |
exclude: /(node_modules|bower_components)/, | |
}, | |
], | |
}, | |
plugins: [ | |
new webpack.ProgressPlugin(), | |
new CleanWebpackPlugin(), | |
new HtmlWebpackPlugin({ | |
template: path.resolve(__dirname, "index.html"), | |
}), | |
new MiniCssExtractPlugin(), | |
new OptimizeCSSAssetsPlugin(), | |
], | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment