Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calypso-build: remove dependency on calypso-color-schemes #36471

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion packages/calypso-build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"extends @wordpress/browserslist-config"
],
"dependencies": {
"@automattic/calypso-color-schemes": "file:../calypso-color-schemes",
"@babel/core": "7.6.2",
"@babel/plugin-proposal-class-properties": "7.5.5",
"@babel/plugin-syntax-dynamic-import": "7.2.0",
Expand Down
6 changes: 4 additions & 2 deletions packages/calypso-build/postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
module.exports = ( { options: { preserveCssCustomProperties = true } } ) => ( {
module.exports = ( {
options: { preserveCssCustomProperties = true, importCssCustomPropertiesFrom },
} ) => ( {
plugins: {
'postcss-custom-properties': {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could postcss-custom-properties plugin be left out if importCssCustomPropertiesFrom is falsey? That would effectively make this opt-in.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@simison postcss-custom-properties is useful even in the default configuration when neither of the "preserve" and "import from" options are passed. It then converts:

:root {
  --color: red;
}

h1 {
  color: var( --color );
}

to

:root {
  --color: red;
}

h1 {
  color: red;
  color: var( --color );
}

It inlines the default variable as a fallback. Think of it as a IE11 polyfill.

The "import from" option is needed only when the variables are defined in a different stylesheet. node-sass and postcss process stylesheets one by one, exactly as they are stored in sources. Only at the very end does webpack merge them together.

importFrom: [ require.resolve( '@automattic/calypso-color-schemes' ) ],
importFrom: importCssCustomPropertiesFrom,
preserve: preserveCssCustomProperties,
},
autoprefixer: {},
Expand Down
5 changes: 1 addition & 4 deletions packages/calypso-build/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,7 @@ function getWebpackConfig(
presets,
workerCount,
} ),
SassConfig.loader( {
preserveCssCustomProperties: false,
prelude: '@import "~@automattic/calypso-color-schemes/src/shared/colors";',
} ),
SassConfig.loader(),
FileConfig.loader(),
],
},
Expand Down
8 changes: 7 additions & 1 deletion packages/calypso-build/webpack/sass.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ const path = require( 'path' );
*
* @return {Object} webpack loader object
*/
module.exports.loader = ( { preserveCssCustomProperties, includePaths, prelude } ) => ( {
module.exports.loader = ( {
preserveCssCustomProperties,
importCssCustomPropertiesFrom,
includePaths,
prelude,
} = {} ) => ( {
test: /\.(sc|sa|c)ss$/,
use: [
MiniCssExtractPluginWithRTL.loader,
Expand All @@ -32,6 +37,7 @@ module.exports.loader = ( { preserveCssCustomProperties, includePaths, prelude }
config: {
ctx: {
preserveCssCustomProperties,
importCssCustomPropertiesFrom,
},
path: path.join( __dirname, '..' ),
},
Expand Down
1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ const webpackConfig = {
include: shouldTranspileDependency,
} ),
SassConfig.loader( {
importCssCustomPropertiesFrom: [ require.resolve( '@automattic/calypso-color-schemes' ) ],
preserveCssCustomProperties: true,
includePaths: [ path.join( __dirname, 'client' ) ],
prelude: `@import '${ path.join(
Expand Down