Skip to content

Instantly share code, notes, and snippets.

@ivan-vilches
Created September 14, 2019 20:13
Show Gist options
  • Save ivan-vilches/17f853837c7bc5f7676b122d3a202f2f to your computer and use it in GitHub Desktop.
Save ivan-vilches/17f853837c7bc5f7676b122d3a202f2f to your computer and use it in GitHub Desktop.
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");
const MinifyPlugin = require("babel-minify-webpack-plugin");
const path = require('path');
module.exports = function (env, argv) {
return {
mode: 'production',
entry: [
'./src/app.js'
],
optimization: {
minimizer: [
new OptimizeCSSAssetsPlugin()
]
}
,
plugins: [
new CleanWebpackPlugin(['dist']),
new HtmlWebpackPlugin({
title: 'Webpack starter project',
template: path.resolve('./src/index.html')
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[id].css"
}),
new MinifyPlugin()
],
module: {
rules: [
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader"
]
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.(pdf|doc|docx|xls|xlsx|txt|csv|tsv)$/,
use: [
{
loader: "file-loader",
options: {
outputPath: './files',
name: "[name].[ext]",
},
}
]
},
{
test: /\.(jpg|jpeg|gif|png|svg|webp)$/,
use: [
{
loader: "file-loader",
options: {
outputPath: './images',
name: "[name].[ext]",
},
},
{
loader: 'image-webpack-loader',
options: {
mozjpeg: {
progressive: false,
quality: 45
},
// optipng.enabled: false will disable optipng
optipng: {
enabled: true,
},
pngquant: {
quality: '65-90',
speed: 4
},
gifsicle: {
interlaced: true,
optimizationLevel: 3
},
// the webp option will enable WEBP
webp: {
quality: 20
}
}
},
],
},
{
test: /\.(woff(2)?|ttf|otf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}
]
},
{
test: /\.html$/,
use: {
loader: 'html-loader',
options: {
attrs: [':src', ':href']
}
}
},
]
}
};
}
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const path = require('path');
module.exports = function(){
return {
mode: 'development',
entry: [
'./src/app.js'
],
watch: true,
watchOptions: {
aggregateTimeout: 300, // Process all changes which happened in this time into one rebuild
poll: 1000, // Check for changes every second,
ignored: /node_modules/,
// ignored: [
// '**/*.scss', '/node_modules/'
// ]
},
devtool: 'source-maps',
devServer: {
contentBase: path.join(__dirname, 'src'),
watchContentBase: true,
hot: true,
open: true,
inline: true
},
plugins: [
new HtmlWebpackPlugin({
title: 'Webpack starter project',
template: path.resolve('./src/index.html')
}),
new webpack.HotModuleReplacementPlugin()
],
module: {
rules: [
{
test: /\.scss$/,
use: [
'style-loader',
"css-loader",
"sass-loader"
]
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
{
test: /\.(pdf|doc|docx|xls|xlsx|txt|csv|tsv)$/,
use: [
{
loader: "file-loader",
options: {
outputPath: './files',
name: "[name].[ext]",
},
}
]
},
{
test: /\.(jpg|jpeg|gif|png|svg|webp)$/,
use: [
{
loader: "file-loader",
options: {
outputPath: './images',
name: "[name].[ext]",
},
},
]
},
{
test: /\.(woff(2)?|ttf|otf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'fonts/'
}
}
]
},
{
test: /\.html$/,
use: {
loader: 'html-loader',
options: {
attrs: [':src', ':href']
}
}
},
]
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment