Skip to content

Commit 1b4a6bd

Browse files
committed
improve: reorganize build system with better project structure
* Move build.js to scripts/build.js for better organization * Create scripts/dev-build.js for development setup workflow * Update package.json scripts to reference new file locations * Move micromodal from js/ to vendor/micromodal/ directory * Update assets.php to load micromodal from vendor location * Switch from zip-a-folder to archiver for more stable ZIP creation * Move micromodal from dependencies to devDependencies in package.json * Update build process to include vendor directory in distribution * Improve error handling and logging in build scripts Follows WordPress best practices and improves developer experience without changing end-user functionality.
1 parent 0e5a07b commit 1b4a6bd

File tree

18 files changed

+2341
-29
lines changed

18 files changed

+2341
-29
lines changed

README.md

Lines changed: 62 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,29 @@ Kntnt Popup offers multiple ways to control when and how popups appear and disap
7171
### Time-based trigger
7272

7373
**Delayed display:** Show a popup after a specified number of seconds:
74+
7475
```
7576
[popup show-after-time="10"]This popup appears after 10 seconds.[/popup]
7677
```
7778

7879
**Immediate display:** Show a popup as soon as the page loads:
80+
7981
```
8082
[popup show-after-time="0"]This popup appears immediately when the page loads.[/popup]
8183
```
8284

8385
### Scroll-based trigger
8486

8587
Show a popup when the user has scrolled a certain percentage of the page:
88+
8689
```
8790
[popup show-after-scroll="75"]This popup appears when you've scrolled 75% of the page.[/popup]
8891
```
8992

9093
### Exit intent trigger
9194

9295
Trigger a popup when the user moves their mouse cursor toward the browser's address bar or tab area, indicating they might be about to leave:
96+
9397
```
9498
[popup show-on-exit-intent]Wait! Don't leave yet. Check out this special offer![/popup]
9599
```
@@ -140,25 +144,29 @@ Kntnt Popup provides several ways for users to close popups, giving you complete
140144
### Built-in close button
141145

142146
Add a close button (×) in the top-right corner of the popup:
147+
143148
```
144149
[popup close-button]This popup has a close button.[/popup]
145150
```
146151

147152
You can customize the close button character:
153+
148154
```
149155
[popup close-button="✕"]This popup uses a different close icon.[/popup]
150156
```
151157

152158
### Click outside to close
153159

154160
Allow users to close the popup by clicking anywhere outside the popup area:
161+
155162
```
156163
[popup close-outside-click]Click outside this popup to close it.[/popup]
157164
```
158165

159166
### ESC key to close
160167

161168
Enable closing the popup by pressing the ESC key:
169+
162170
```
163171
[popup close-esc-key]Press ESC to close this popup.[/popup]
164172
```
@@ -168,6 +176,7 @@ Enable closing the popup by pressing the ESC key:
168176
Make any element inside or outside the popup close it by adding the `data-popup-close` attribute:
169177

170178
**Close link inside popup content:**
179+
171180
```
172181
[popup modal show-after-time="5"]
173182
<h2>Welcome!</h2>
@@ -177,6 +186,7 @@ Make any element inside or outside the popup close it by adding the `data-popup-
177186
```
178187

179188
**Close button inside popup:**
189+
180190
```
181191
[popup show-after-scroll="50"]
182192
<h2>Newsletter Signup</h2>
@@ -189,6 +199,7 @@ Make any element inside or outside the popup close it by adding the `data-popup-
189199
```
190200

191201
**External close trigger (anywhere on the page):**
202+
192203
```html
193204
<!-- This button can be anywhere on your page -->
194205
<button data-popup-close>Close any open popup</button>
@@ -788,11 +799,11 @@ document.addEventListener('kntnt_popup:after_close', function (event) {
788799
789800
## Building from Source (for Developers)
790801
791-
If you have downloaded the plugin source code directly from GitHub, the necessary JavaScript file (`js/micromodal.min.js`) might not be included or might be outdated. This file is managed using Node.js and npm. Follow these steps to install dependencies and build the required JavaScript file:
802+
If you have downloaded the plugin source code directly from GitHub, you'll need to install dependencies and build the plugin for distribution.
792803

793-
### 1. Install Node.js and npm
804+
### Development Setup
794805

795-
You need Node.js installed on your system, which includes npm (Node Package Manager). If you don't have it installed, download and install the LTS (Long Term Support) version from the official website:
806+
For development work, you need Node.js installed on your system, which includes npm (Node Package Manager). If you don't have it installed, download and install the LTS (Long Term Support) version from the official website:
796807
797808
* [https://nodejs.org/](https://nodejs.org/)
798809
@@ -803,53 +814,69 @@ node -v
803814
npm -v
804815
```
805816
806-
### 2. Install Project Dependencies
817+
### Install Dependencies
807818
808-
Navigate to the plugin's root directory (`kntnt-popup/`) in your terminal and run the following command:
819+
Navigate to the plugin's root directory (`kntnt-popup/`) in your terminal and run:
809820

810821
```bash
811822
npm install
812823
```
813824

814-
This command reads the package.json file and downloads the required development dependencies (like Micromodal.js) into a node_modules folder within the plugin directory.
825+
This command reads the package.json file and downloads the required dependencies into a node_modules folder.
815826

816-
### 3. Build the JavaScript File
827+
### Development Build
817828

818-
After the dependencies are installed, run the build command defined in `package.json`:
829+
For development purposes (to get the MicroModal.js dependency), run:
819830

820831
```bash
821-
npm run build
832+
npm run dev-build
822833
```
823834

824-
This command executes the build script, which typically copies the necessary JavaScript file (`micromodal.min.js`) from `node_modules` to the correct location within the plugin's `js/` directory.
835+
This copies the necessary JavaScript file (`micromodal.min.js`) from `node_modules` to the correct location within the plugin's `vendor/micromodal/` directory.
825836
826-
### 4. Updating Dependencies
837+
### Production Build
827838
828-
To check if there are newer versions of the dependencies (like Micromodal.js):
839+
To create a production-ready version of the plugin:
829840
830841
```bash
831-
npm outdated
842+
npm run build
832843
```
833844
834-
To update a specific dependency (e.g., micromodal) to the latest version allowed by package.json:
845+
This command:
835846
836-
```bash
837-
npm update micromodal
838-
```
847+
1. Cleans the `dist` directory
848+
2. Copies all necessary plugin files to `dist/kntnt-popup/`
849+
3. Minifies and optimizes the CSS file using cssnano
850+
4. Minifies and optimizes the JavaScript file using terser
851+
5. Creates a `dist/kntnt-popup.zip` file ready for distribution
852+
853+
The production build creates optimized files that are smaller and faster to load, making them ideal for production environments.
854+
855+
### Build Output
856+
857+
After running `npm run build`, you'll find:
858+
859+
- `dist/kntnt-popup/` - The complete plugin directory with optimized files
860+
- `dist/kntnt-popup.zip` - A ZIP archive ready for WordPress installation
861+
862+
### Updating Dependencies
839863

840-
Or update all dependencies:
864+
To check if there are newer versions of the dependencies:
841865

842866
```bash
843-
npm update
867+
npm outdated
844868
```
845869

846-
**Important:** After updating dependencies with npm update, you must run the build command again to copy the updated file(s) to the js/ directory:
870+
To update dependencies:
847871

848872
```bash
849-
npm run build
873+
npm update
850874
```
851875

852-
Now you have the necessary JavaScript file in place, and the plugin should function correctly.
876+
**Important:** After updating dependencies, you must run the appropriate build command again:
877+
878+
- For development: `npm run dev-build`
879+
- For production: `npm run build`
853880

854881
## Questions & Answers
855882

@@ -869,6 +896,19 @@ If you are not familiar with Git, please create a new ticket on the plugin's iss
869896
870897
## Changelog
871898
899+
## 1.1.1 (2025-05-24)
900+
901+
- enhance: add modern build system with npm scripts for development and production
902+
- enhance: implement CSS minification using cssnano for optimized file sizes
903+
- enhance: implement JavaScript minification using terser for better performance
904+
- enhance: add automated ZIP file generation for easy distribution
905+
- enhance: reorganize build scripts into dedicated `scripts/` directory for better project structure
906+
- enhance: move third-party dependencies to `vendor/` directory following WordPress best practices
907+
- enhance: improve dependency management with separate dev and production workflows
908+
- improve: restructure development workflow with separate dev and production builds
909+
- improve: add comprehensive build documentation for developers
910+
- improve: switch from zip-a-folder to archiver for more reliable ZIP generation
911+
872912
## 1.1.0 (2025-05-23)
873913
874914
- feature: add new `close-esc-key` parameter to control whether ESC key closes the popup

classes/assets.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function register_assets(): void {
3434

3535
// Register Micromodal library script (dependency for main script).
3636
wp_register_script( Plugin::get_slug() . '-micromodal', // Handle
37-
Plugin::get_plugin_url() . 'js/micromodal.min.js', // Source URL
37+
Plugin::get_plugin_url() . 'vendor/micromodal/micromodal.min.js', // Source URL
3838
[], // Dependencies
3939
Plugin::get_version(), // Version
4040
true // In footer

dist/kntnt-popup.zip

28.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)