Last active
April 1, 2020 16:31
-
-
Save asharirfan/7420126571c1e47365a1d53744794a34 to your computer and use it in GitHub Desktop.
Webpack config to extend the default configurations of wp-scripts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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