Skip to content

Commit 8f940c2

Browse files
authored
Merge pull request #1022 from Kit/build-minify-frontend-css
Build and Minify Frontend CSS
2 parents 74187c2 + aba4156 commit 8f940c2

40 files changed

Lines changed: 760 additions & 612 deletions

.distignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/.wordpress-org
66
/log
77
/node_modules
8+
/resources/frontend/css/*.map
89
/tests
910
/vendor/autoload.php
1011
/vendor/composer

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ log.txt
88
package-lock.json
99
phpstan.neon
1010
node_modules
11+
resources/frontend/css/*.map
1112
tests/_output
1213
tests/_wordpress
1314
tests/Support/_generated

.stylelintrc.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"extends": "@wordpress/stylelint-config",
3+
"plugins": ["stylelint-scss"],
34
"rules": {
45
"font-family-no-missing-generic-family-keyword": null,
56
"selector-class-pattern": null,
6-
"declaration-property-unit-allowed-list": null
7+
"declaration-property-unit-allowed-list": null,
8+
"at-rule-no-unknown": [true, {
9+
"ignoreAtRules": ["use", "forward", "mixin", "include", "extend"]
10+
}]
711
}
812
}

DEVELOPMENT.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,18 @@ Typically, packages listed in this section would be internal development tools f
6060
- PHPStan
6161
- Codeception
6262

63+
### Build
64+
65+
Run `npm run build` to compile frontend CSS and JS in one step.
66+
67+
### CSS
68+
69+
Run `npm run watch:css` to compile frontend CSS to `resources/frontend/css/frontend.css` when working on SCSS in the `resources/frontend/scss` folder.
70+
71+
### JS
72+
73+
Run `npm run watch:js` to compile frontend JS to `resources/frontend/js/dist/frontend-min.js` when working on JS in the `resources/frontend/js` folder.
74+
6375
## Committing Work
6476

6577
Remember to commit your changes to your branch relatively frequently, with a meaningful, short summary that explains what the change(s) do.

SETUP.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,9 @@ In the Plugin's directory, at the command line, run `npm install`.
9393

9494
This sets up:
9595
- JS linting / coding standards using WordPress recommended configurations (https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/#lint-js)
96-
- CSS linting / coding standards using WordPress recommended configurations (https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/#lint-style)
96+
- SCSS and CSS linting / coding standards using WordPress recommended configurations (https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/#lint-style)
97+
- JS compilation and minification
98+
- SASS compilation and minification
9799

98100
### Configure wp-config.php
99101

TESTING.md

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,29 @@ The following Composer commands can be used:
2626
| `composer fix-php-coding-standards` | `composer phpcbf` | Fix PHP files to meet WordPress and PHP Coding Standards |
2727
| `composer php-coding-standards-on-tests` | `composer phpcs-tests` | Runs PHP Coding Standards on the /tests folder |
2828
| `composer fix-php-coding-standards-on-tests` | `composer phpcbf-tests` | Fix PHP files to meet PHP Coding Standards on the /tests folder |
29-
| `composer css-coding-standards` | `composer lint-css` | Runs WordPress CSS Coding Standards on the entire plugin codebase |
29+
| `composer css-coding-standards` | `composer lint-css` | Runs WordPress CSS Coding Standards on CSS and SCSS files |
3030
| `composer fix-css-coding-standards` | `composer fix-css` | Fixes CSS files to meet WordPress CSS Coding Standards |
31-
| `composer js-coding-standards` | `composer lint-js` | Runs WordPress JS Coding Standards on the entire plugin codebase |
31+
| `composer build-css` | `composer build-css` | Builds the frontend CSS file |
32+
| `composer watch-css` | `composer watch-css` | Builds the frontend CSS file when changes are made to SCSS files |
33+
| `composer js-coding-standards` | `composer lint-js` | Runs WordPress JS Coding Standards on JS files |
3234
| `composer fix-js-coding-standards` | `composer fix-js` | Fixes JS files to meet WordPress JS Coding Standards |
35+
| `composer build-js` | `composer build-js` | Builds the frontend JS file |
36+
| `composer watch-js` | `composer watch-js` | Builds the frontend JS file when changes are made to frontend JS files |
37+
| `composer build` | `composer build` | Builds frontend CSS and JS |
3338
| `composer static-analysis` | `composer phpstan` | Runs PHPStan static analysis with increased memory limit |
3439
| `composer test` | `composer test` | Builds and runs end-to-end tests with `fail-fast` enabled |
3540
| `composer test-integration` | `composer test-integration` | Builds and runs integration tests with `fail-fast` enabled |
3641

42+
The following npm commands can be used, if preferred:
43+
44+
| Command | Description |
45+
|---------|-------------|
46+
| `npm run build:css` | Builds the frontend CSS file |
47+
| `npm run watch:css` | Builds the frontend CSS file when changes are made to SCSS files |
48+
| `npm run build:js` | Builds the frontend JS file |
49+
| `npm run watch:js` | Builds the frontend JS file when changes are made to frontend JS files |
50+
| `npm run build` | Builds frontend CSS and JS |
51+
3752
## Write (or modify) a test
3853

3954
If your work creates new functionality, write a test.

composer.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,18 @@
2727
"phpcbf": "vendor/bin/phpcbf ./ -s -v",
2828
"phpcs-tests": "vendor/bin/phpcs ./tests --standard=phpcs.tests.xml -s -v",
2929
"phpcbf-tests": "vendor/bin/phpcbf ./tests --standard=phpcs.tests.xml -s -v",
30+
"build-css": "npm run build:css",
31+
"watch-css": "npm run watch:css",
3032
"lint-css": "npm run lint:css",
3133
"fix-css": "npm run fix:css",
34+
"build-js": "npm run build:js",
35+
"watch-js": "npm run watch:js",
3236
"lint-js": "npm run lint:js",
3337
"fix-js": "npm run fix:js",
38+
"build": [
39+
"npm run build:css",
40+
"npm run build:js"
41+
],
3442
"phpstan": "vendor/bin/phpstan analyse --memory-limit=1250M",
3543
"php-coding-standards": "vendor/bin/phpcs ./ -s -v",
3644
"fix-php-coding-standards": "vendor/bin/phpcbf ./ -s -v",

includes/blocks/class-convertkit-block-broadcasts.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,12 @@ public function enqueue_scripts() {
115115
// Get ConvertKit Settings.
116116
$settings = new ConvertKit_Settings();
117117

118-
wp_enqueue_script( 'convertkit-' . $this->get_name(), CONVERTKIT_PLUGIN_URL . 'resources/frontend/js/broadcasts.js', array(), CONVERTKIT_PLUGIN_VERSION, true );
118+
// Enqueue frontend JS.
119+
convertkit_enqueue_frontend_js();
120+
121+
// Define variables.
119122
wp_localize_script(
120-
'convertkit-' . $this->get_name(),
123+
'convertkit-js',
121124
'convertkit_broadcasts',
122125
array(
123126
// REST API URL endpoint.
@@ -127,6 +130,7 @@ public function enqueue_scripts() {
127130
'debug' => $settings->debug_enabled(),
128131
)
129132
);
133+
130134
}
131135

132136
/**
@@ -136,7 +140,7 @@ public function enqueue_scripts() {
136140
*/
137141
public function enqueue_styles() {
138142

139-
wp_enqueue_style( 'convertkit-' . $this->get_name(), CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/broadcasts.css', array(), CONVERTKIT_PLUGIN_VERSION );
143+
convertkit_enqueue_frontend_css();
140144

141145
}
142146

includes/blocks/class-convertkit-block-form-builder-field.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public function enqueue_styles_editor() {
8989
*/
9090
public function enqueue_styles() {
9191

92-
wp_enqueue_style( 'convertkit-form-builder', CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/form-builder.css', array(), CONVERTKIT_PLUGIN_VERSION );
92+
convertkit_enqueue_frontend_css();
9393

9494
}
9595

includes/blocks/class-convertkit-block-form-builder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public function enqueue_styles_editor() {
288288
*/
289289
public function enqueue_styles() {
290290

291-
wp_enqueue_style( 'convertkit-form-builder-field', CONVERTKIT_PLUGIN_URL . 'resources/frontend/css/form-builder.css', array(), CONVERTKIT_PLUGIN_VERSION );
291+
convertkit_enqueue_frontend_css();
292292

293293
}
294294

0 commit comments

Comments
 (0)