Skip to content
Merged
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
3 changes: 2 additions & 1 deletion bin/build-plugin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ fi
status "Installing dependencies..."
npm install
status "Generating build..."
npm run build
# Skip the webpack cache so the release is built from scratch.
npm run build -- --no-cache
status "Minimizing JS..."
npm run minimize

Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
"scripts": {
"test:unit": "node --test tests/js/*.test.mjs",
"build": "cross-env NODE_ENV=production webpack --progress",
"build:js": "cross-env NODE_ENV=production webpack --config-name js",
"build:css": "cross-env NODE_ENV=production webpack --config-name css",
"dev": "cross-env NODE_ENV=default webpack --watch",
"watch": "npm run dev",
"serve": "node -e \"const prompts=require('prompts');(async()=>{const responses=await prompts([{type:'text',name:'domain',message:'WordPress site domain',initial:'formidable.local'},{type:'text',name:'watch',message:'Enable JS/PHP watching (N/Y)',initial:'N'}]);process.env.SITE_DOMAIN=responses.domain;process.env.ENABLE_WATCH=responses.watch;require('./webpack.dev.js')})()\"",
"serve": "node -e \"const prompts=require('prompts');(async()=>{const responses=await prompts([{type:'text',name:'domain',message:'WordPress site domain',initial:'formidable.local'}]);process.env.SITE_DOMAIN=responses.domain;require('./webpack.dev.js')})()\"",
"lint": "./node_modules/.bin/eslint .",
"lint:fix": "./node_modules/.bin/eslint . --fix",
"test:js": "node --test tests/js/*.test.mjs",
Expand Down
8 changes: 8 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ const entries = {
const sharedConfig = {
mode: isDevelopment ? 'development' : 'production',
devtool: isDevelopment ? 'source-map' : undefined,
// Keep build results on disk so a rebuild only reprocesses the files that changed.
// Editing this file or .babelrc throws the cache away. Pass --no-cache for a clean build.
cache: {
type: 'filesystem',
buildDependencies: {
config: [__filename, path.resolve(__dirname, '.babelrc')]
}
},
resolve: {
extensions: ['.json', '.js', '.jsx', '.scss', '.css'],
modules: [paths.jsSource, 'node_modules'],
Expand Down
26 changes: 3 additions & 23 deletions webpack.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
* Formidable Forms Development Server
*
* Run `npm run serve` to start the development server. You'll be prompted
* for your WordPress site URL and JS/PHP watching, then a dev server starts at localhost:8880.
* for your WordPress site URL, then a dev server starts at localhost:8880.
*
* Development is streamlined with automatic updates:
* - CSS/SCSS changes are injected in real-time without page refresh
* - JavaScript and PHP changes trigger an automatic full page reload (opt-in)
* - JavaScript is rebuilt on change. Reload the page to see it.
* - Browser opens automatically to localhost:8880
*/

Expand All @@ -30,9 +29,7 @@ const config = {

// Paths to watch for changes
cssPath: '../formidable*/**/*.css',
jsPath: '../formidable*/**/*.js',
jsSrcPath: '../formidable*/*/js/src/**/*.js',
phpPath: '../formidable*/**/*.php',

// Public path for webpack
publicPath: '/wp-content/plugins/formidable/css/'
Expand Down Expand Up @@ -89,24 +86,7 @@ const init = () => {
{
match: [ config.jsSrcPath ],
fn: ( event, file ) => console.log( `JS source updated: ${ file }\nRebuilding JS bundles...` )
},
// Conditionally watch compiled JS and PHP files for full page reload
...( process.env.ENABLE_WATCH && process.env.ENABLE_WATCH.toLowerCase().startsWith( 'y' ) ? [
{
match: [ config.jsPath ],
fn: ( event, file ) => {
console.log( `JS updated: ${ file }` );
browserSyncInstance.reload();
}
},
{
match: [ config.phpPath ],
fn: ( event, file ) => {
console.log( `PHP updated: ${ file }` );
browserSyncInstance.reload();
}
}
] : [] )
}
],

// Server settings
Expand Down