Skip to content

Commit

Permalink
Scripts: Add PostCSS (.pcss extension) file support to wp-scripts (#4…
Browse files Browse the repository at this point in the history
…5352)

* Add pcss file extension to splitChunks cache group test regex.

* Add .pcss loader rule for processing PostCSS files via the existing cssLoaders config.

* Add PostCSS files (.pcss extension) to SVG asset-inlining loader to allow inlining SVGs from PostCSS files.

* Add PostCSS files (.pcss extension) default stylelint rules.

* Add PostCSS (.pcss extension) file support to README.md

* Add CHANGELOG.md entry.

* Add PR number to changelog entry.

---------

Co-authored-by: Greg Ziółkowski <grzegorz@gziolo.pl>
  • Loading branch information
dpellenwood and gziolo authored Feb 2, 2023
1 parent 5d2a294 commit 05bea6d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/scripts/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### New Features

- The `WP_DEVTOOL` environment variable can now be used to set the Webpack devtool option for sourcemaps in production builds ([#46812](https://github.com/WordPress/gutenberg/pull/46812)). Previously, this only worked for development builds.
- Update default webpack config and lint-style script to allow PostCSS (`.pcss` extension) file usage ([#45352](https://github.com/WordPress/gutenberg/pull/45352)).

## 25.3.0 (2023-02-01)

Expand Down
5 changes: 3 additions & 2 deletions packages/scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ _Example:_

This is how you execute the script with presented setup:

- `npm run lint:style` - lints CSS and SCSS files in the entire project’s directories.
- `npm run lint:style` - lints CSS, PCSS, and SCSS files in the entire project’s directories.
- `npm run lint:css:src` - lints only CSS files in the project’s `src` subfolder’s directories.

When you run commands similar to the `npm run lint:css:src` example above, be sure to include the quotation marks around file globs. This ensures that you can use the powers of [globby](https://github.com/sindresorhus/globby) (like the `**` globstar) regardless of your shell. See [more examples](https://github.com/stylelint/stylelint/blob/HEAD/docs/user-guide/cli.md#examples).
Expand Down Expand Up @@ -587,14 +587,15 @@ $body-color: red;

```js
// index.js
import './index.pcss';
import './index.scss';
import './style.css';
```

When you run the build using the default command `wp-scripts build` (also applies to `start`) in addition to the JavaScript file `index.js` generated in the `build` folder, you should see two more files:

1. `index.css` – all imported CSS files are bundled into one chunk named after the entry point, which defaults to `index.js`, and thus the file created becomes `index.css`. This is for styles used only in the editor.
2. `style-index.css` – imported `style.css` file(s) (applies to SASS and SCSS extensions) get bundled into one `style-index.css` file that is meant to be used both on the front-end and in the editor.
2. `style-index.css` – imported `style.css` file(s) (applies to PCSS, SASS and SCSS extensions) get bundled into one `style-index.css` file that is meant to be used both on the front-end and in the editor.

You can also have multiple entry points as described in the docs for the script:

Expand Down
8 changes: 6 additions & 2 deletions packages/scripts/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const config = {
cacheGroups: {
style: {
type: 'css/mini-extract',
test: /[\\/]style(\.module)?\.(sc|sa|c)ss$/,
test: /[\\/]style(\.module)?\.(pc|sc|sa|c)ss$/,
chunks: 'all',
enforce: true,
name( _, chunks, cacheGroupKey ) {
Expand Down Expand Up @@ -180,6 +180,10 @@ const config = {
test: /\.css$/,
use: cssLoaders,
},
{
test: /\.pcss$/,
use: cssLoaders,
},
{
test: /\.(sc|sa)ss$/,
use: [
Expand All @@ -200,7 +204,7 @@ const config = {
},
{
test: /\.svg$/,
issuer: /\.(sc|sa|c)ss$/,
issuer: /\.(pc|sc|sa|c)ss$/,
type: 'asset/inline',
},
{
Expand Down
2 changes: 1 addition & 1 deletion packages/scripts/scripts/lint-style.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const {

const args = getArgsFromCLI();

const defaultFilesArgs = hasFileArgInCLI() ? [] : [ '**/*.{css,scss}' ];
const defaultFilesArgs = hasFileArgInCLI() ? [] : [ '**/*.{css,pcss,scss}' ];

// See: https://stylelint.io/user-guide/configuration
const hasLintConfig =
Expand Down

1 comment on commit 05bea6d

@github-actions
Copy link

Choose a reason for hiding this comment

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

Flaky tests detected in 05bea6d.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/4073397949
📝 Reported issues:

Please sign in to comment.