Skip to content

Instantly share code, notes, and snippets.

@lokesh1729
Created May 12, 2020 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lokesh1729/8b59cbe3673acaab78a3638556bf3f9d to your computer and use it in GitHub Desktop.
Save lokesh1729/8b59cbe3673acaab78a3638556bf3f9d to your computer and use it in GitHub Desktop.
yahoooo!!! my first webpack config working fine :)
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