Skip to content

Instantly share code, notes, and snippets.

@asharirfan
Last active April 1, 2020 16:31
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 asharirfan/7420126571c1e47365a1d53744794a34 to your computer and use it in GitHub Desktop.
Save asharirfan/7420126571c1e47365a1d53744794a34 to your computer and use it in GitHub Desktop.
Webpack config to extend the default configurations of wp-scripts
/**
* Webpack Custom Config.
*/
const path = require("path");
const postcssPresetEnv = require("postcss-preset-env");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
const defaultConfig = require("@wordpress/scripts/config/webpack.config");
const { mode, entry, output, resolve, plugins, stats } = defaultConfig;
module.exports = {
mode,
entry,
output,
resolve,
optimization: {
splitChunks: {
chunks: "all",
cacheGroups: {
style: {
name: "style",
test: /style\.(sc|sa|c)ss$/,
enforce: true
},
default: false
}
}
},
module: {
...defaultConfig.module,
rules: [
...defaultConfig.module.rules,
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "postcss-loader",
options: {
ident: "postcss",
plugins: () => [
// postcssPresetEnv(),
postcssPresetEnv({
stage: 3,
browsers: [
">1%",
"last 4 versions",
"Firefox ESR",
"not ie < 9" // React doesn't support IE8 anyway
]
})
]
}
},
"sass-loader"
]
}
]
},
plugins: [
new FixStyleOnlyEntriesPlugin({
silent: false
}),
new MiniCssExtractPlugin({
filename: "[name].css",
chunkFilename: "[name].css"
}),
...plugins
],
stats
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment