diff --git a/bin/build-plugin.sh b/bin/build-plugin.sh index 6317def90b..f0dd25893a 100755 --- a/bin/build-plugin.sh +++ b/bin/build-plugin.sh @@ -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 diff --git a/package.json b/package.json index 603135b31e..976f76b0d6 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/webpack.config.js b/webpack.config.js index b312831f59..4553689e28 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -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'], diff --git a/webpack.dev.js b/webpack.dev.js index 7362735834..72e4bd0e7b 100755 --- a/webpack.dev.js +++ b/webpack.dev.js @@ -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 */ @@ -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/' @@ -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