Skip to content

Instantly share code, notes, and snippets.

@amphineko
Created September 22, 2019 23:12
Show Gist options
  • Save amphineko/1fb556a180efe5312cc890660df89d91 to your computer and use it in GitHub Desktop.
Save amphineko/1fb556a180efe5312cc890660df89d91 to your computer and use it in GitHub Desktop.
cursed webpack
const path = require('path')
const { CleanWebpackPlugin: CleanPlugin } = require('clean-webpack-plugin')
const HtmlPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production'
return {
bail: true, // stop on first error
context: path.resolve(__dirname, 'src'),
mode: isProduction ? 'production' : 'development',
entry: {
index: './index.js'
},
module: {
rules: [
{
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/,
use: {
loader: 'file-loader',
options: {
name: '[path][name].[contenthash:8].[ext]'
}
}
},
{
test: /\.(c|sa|sc)ss$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader",
options: {
sourceMap: !isProduction
}
},
{
loader: "sass-loader",
options: {
outputStyle: 'expanded',
sourceMap: true,
sourceMapContents: true
}
}
]
}
]
},
output: {
filename: '[name].[contenthash:8].js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new CleanPlugin(),
new HtmlPlugin({
template: './index.html'
}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash:8].css',
chunkFilename: '[name].[id].css'
})
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment