Skip to content

Commit

Permalink
Simplify namespacing inclusion/exclusion
Browse files Browse the repository at this point in the history
  • Loading branch information
simison committed Aug 17, 2018
1 parent 07e5716 commit 25955c6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
1 change: 0 additions & 1 deletion bin/sdk/gutenberg.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ exports.config = ( {
const baseConfig = getBaseConfig( {
externalizeWordPressPackages: true,
stylesNamespacing: 'calypso',
stylesNamespacingExclude: path.join( __rootDir, 'client', 'gutenberg' ),
} );
const name = path.basename( path.dirname( editorScript ).replace( /\/$/, '' ) );

Expand Down
31 changes: 15 additions & 16 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ const sassLoader = {
},
};

// When styles-namespacing is enabled, these are the files we want to namespace
const stylesNamespacingDirectories = [ path.join( __dirname, 'client', 'components' ) ];

/**
* Converts @wordpress require into window reference
*
Expand Down Expand Up @@ -128,16 +131,11 @@ const wordpressExternals = ( context, request, callback ) =>
*
* @param {object} env environment options
* @param {boolean} env.externalizeWordPressPackages whether to bundle or extern the `@wordpress/` packages
* @param {string} env.stylesNamespacing prefix styles with CSS class or ID
* @param {string} env.stylesNamespacingExclude paths to exlude from namespacing when `stylesNamespacing` is defined
* @param {string} env.stylesNamespacing prefix Calypso component styles with CSS class or ID
*
* @return {object} webpack config
*/
function getWebpackConfig( {
stylesNamespacingExclude = '',
externalizeWordPressPackages = false,
stylesNamespacing = '',
} = {} ) {
function getWebpackConfig( { externalizeWordPressPackages = false, stylesNamespacing = '' } = {} ) {
const webpackConfig = {
bail: ! isDevelopment,
context: __dirname,
Expand Down Expand Up @@ -203,20 +201,21 @@ function getWebpackConfig( {
},
{
test: /\.(sc|sa|c)ss$/,
use: _.compact( [
use: [ ...preSassLoaders, sassLoader ],
// When styles-namespacing is enabled, these files are handled by separate loader below
...( stylesNamespacing ? { exclude: stylesNamespacingDirectories } : {} ),
},
stylesNamespacing && {
test: /\.(sc|sa|c)ss$/,
include: stylesNamespacingDirectories,
use: [
...preSassLoaders,
stylesNamespacing && {
{
loader: 'namespace-css-loader',
options: `.${ stylesNamespacing }`,
},
sassLoader,
] ),
...( stylesNamespacingExclude ? { exclude: stylesNamespacingExclude } : {} ),
},
stylesNamespacingExclude && {
test: /\.(sc|sa|c)ss$/,
include: stylesNamespacingExclude,
use: [ ...preSassLoaders, sassLoader ],
],
},
{
test: /extensions[\/\\]index/,
Expand Down

0 comments on commit 25955c6

Please sign in to comment.