Skip to content

Instantly share code, notes, and snippets.

@jarkin13
Last active June 10, 2019 04:14
Show Gist options
  • Save jarkin13/5abee13b443a037e83ba2593f923306f to your computer and use it in GitHub Desktop.
Save jarkin13/5abee13b443a037e83ba2593f923306f to your computer and use it in GitHub Desktop.
Webpack assets
const CompressionPlugin = require('compression-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin')
const ImageminPlugin = require('imagemin-webpack-plugin').default
exports.fonts = ({ include, exclude } = {}) => ({
module: {
rules: [
{
test: /\.(ttf|eot|woff|woff2)$/,
include,
exclude,
use: {
loader: 'file-loader',
options: {
name: 'fonts/[name].[ext]',
publicPath: '../',
},
},
},
],
},
})
exports.images = ({ include, exclude, options } = {}) => {
return {
module: {
rules: [
{
test: /\.(png|jpg)$/,
include,
exclude,
use: [
{
loader: 'file-loader',
options,
},
],
},
],
},
}
}
exports.svg = ({ include, exclude, options } = {}) => ({
module: {
rules: [
{
test: /\.svg$/,
include,
exclude,
use: [
{
loader: 'svg-url-loader',
options,
},
],
},
],
},
})
exports.imagesmin = ({ options, env }) => {
options.disable = env !== 'production'
return {
plugins: [
// Copy the images folder and optimize all the images
new CopyWebpackPlugin(options),
new ImageminPlugin({ test: /\.(jpe?g|png|gif|svg)$/i }),
],
}
}
exports.fontsmin = ({ options, env }) => {
options.disable = env !== 'production'
return {
plugins: [
// Copy the fonts folder and optimize all the fonts
new CopyWebpackPlugin(options),
],
}
}
module.exports = {
plugins: [new CompressionPlugin()],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment