2021-08-19 14:15:59 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2022-03-18 10:59:05 +00:00
|
|
|
const MiniCssExtractPlugin = require( 'mini-css-extract-plugin' );
|
2021-08-19 14:15:59 +00:00
|
|
|
const path = require( 'path' );
|
|
|
|
const WebpackRTLPlugin = require( 'webpack-rtl-plugin' );
|
2022-03-18 10:59:05 +00:00
|
|
|
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
|
2021-08-19 14:15:59 +00:00
|
|
|
const postcssPlugins = require( '@wordpress/postcss-plugins-preset' );
|
|
|
|
|
|
|
|
const NODE_ENV = process.env.NODE_ENV || 'development';
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
webpackConfig: {
|
|
|
|
rules: [
|
|
|
|
{
|
|
|
|
test: /\.s?css$/,
|
|
|
|
exclude: [ /storybook\/wordpress/, /build-style\/*\/*.css/ ],
|
|
|
|
use: [
|
|
|
|
MiniCssExtractPlugin.loader,
|
|
|
|
'css-loader',
|
|
|
|
{
|
|
|
|
loader: 'postcss-loader',
|
|
|
|
options: {
|
2023-03-08 21:13:25 +00:00
|
|
|
postcssOptions: {
|
|
|
|
plugins: postcssPlugins,
|
|
|
|
},
|
2021-08-19 14:15:59 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
loader: 'sass-loader',
|
|
|
|
options: {
|
|
|
|
sassOptions: {
|
|
|
|
includePaths: [
|
|
|
|
path.resolve( __dirname, 'abstracts' ),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
webpackImporter: true,
|
2022-06-08 09:16:31 +00:00
|
|
|
additionalData: ( content, loaderContext ) => {
|
|
|
|
const { resourcePath } = loaderContext;
|
|
|
|
if ( resourcePath.includes( '@automattic+' ) ) {
|
|
|
|
/*
|
|
|
|
* Skip adding additional data for @automattic/* packages to
|
|
|
|
* fix "SassError: @use rules must be written before any other rules."
|
|
|
|
* @automattic/* packages have included '@use "sass:math" and other necessary imports.
|
|
|
|
*/
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
'@use "sass:math";' +
|
|
|
|
'@import "_colors"; ' +
|
|
|
|
'@import "_variables"; ' +
|
|
|
|
'@import "_breakpoints"; ' +
|
|
|
|
'@import "_mixins"; ' +
|
|
|
|
content
|
|
|
|
);
|
|
|
|
},
|
2021-08-19 14:15:59 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
plugins: [
|
2022-03-18 10:59:05 +00:00
|
|
|
new RemoveEmptyScriptsPlugin(),
|
2021-08-19 14:15:59 +00:00
|
|
|
new MiniCssExtractPlugin( {
|
|
|
|
filename: '[name]/style.css',
|
|
|
|
chunkFilename: 'chunks/[id].style.css',
|
|
|
|
} ),
|
|
|
|
new WebpackRTLPlugin( {
|
|
|
|
filename: '[name]/style-rtl.css',
|
|
|
|
minify: NODE_ENV === 'development' ? false : { safe: true },
|
|
|
|
} ),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
};
|