let path = require('path');
let glob = require('glob')
let webpack = require('webpack');
let { CleanWebpackPlugin } = require('clean-webpack-plugin');
let HtmlWebpackPlugin = require('html-webpack-plugin');
let inProduction = process.env.NODE_ENV === 'production'
let PurgecssPlugin = require('purgecss-webpack-plugin')
let MiniCssExtractPlugin = require('mini-css-extract-plugin')
let TerserJSPlugin = require('terser-webpack-plugin');
let OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
let BundleTracker = require('webpack-bundle-tracker');
let PATHS = {
src: path.join(__dirname, 'src')
}
module.exports = {
mode: process.env.NODE_ENV,
entry: ['./src/app.js', './src/app.css'],
output: {
filename: inProduction ? '[name].[chunkhash].js' : '[name].js',
path: path.resolve(__dirname, 'public')
},
plugins: [
new webpack.ProgressPlugin(),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
minify: true,
template: './src/index.html'
}),
new MiniCssExtractPlugin({
filename: inProduction ? '[name].[hash].css' : '[name].css',
chunkFilename: inProduction ? '[id].[hash].css' : '[id].css',
}),
new PurgecssPlugin({
paths: glob.sync(`${PATHS.src}/*`)
}),
new BundleTracker({ filename: './webpack-stats.json' }),
],
module: {
rules: [
{
test: /.(js|jsx)$/,
include: [path.resolve(__dirname, 'src')],
loader: 'babel-loader',
options: {
plugins: ['syntax-dynamic-import'],
presets: [
[
'@babel/preset-env',
{
modules: false
}
]
]
},
},
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: [
require('tailwindcss'),
require('autoprefixer'),
],
}
},
],
},
]
},
optimization: {
minimizer: [new TerserJSPlugin({}), new OptimizeCSSAssetsPlugin({})],
splitChunks: {
cacheGroups: {
vendors: {
priority: -10,
test: /[\\/]node_modules[\\/]/
}
},
chunks: 'async',
minChunks: 1,
minSize: 30000,
name: true
}
},
devServer: {
open: true
}
};
'''
Last active
August 27, 2019 22:49
-
-
Save risha700/084b7d9afd3214f9dd38a24c5d4dac64 to your computer and use it in GitHub Desktop.
webpack configuration for django
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment