I am writing this answer after testing the suggestion given by @SallyCJ (thank you for pointing me towards the right direction)
Writing the following entry into the scripts
section of package.json will change both the source and destination of the React code.
"scripts": {
"build": "wp-scripts build --webpack-src-dir=path/to/source/dir/ --output-path=path/to/destination/dir/",
"test": "echo \"Error: no test specified\" && exit 1"
},
If you’d like to override the default entry point (i.e., use a different file than index.js as your entry point), and if this custom entry point file is located in a custom path, then here is how to setup your scripts
"scripts": {
"build": "wp-scripts build path/to/source/dir/custom.js --webpack-src-dir=path/to/source/dir/ --output-path=path/to/destination/dir/",
"test": "echo \"Error: no test specified\" && exit 1"
},
Related Posts:
- Add a script as a dependency to a registered script
- Setting up an API “listening” page
- Serving wp-includes (front-end) javascript from a different domain?
- Add conversion/tracking pixel to section for specific post
- How can I selectively print scripts to the footer of certain admin pages?
- WP CLI theme install. Install a private repo?
- change $src from wp_register_script in plugins/themes
- By having WordPress in a subfolder does it mean more script executions?
- Script Code in Text Widget Does NOT Show
- Invision + WordPress integration
- wp_print_scripts runs twice
- How to serve wp-includes javascripts from CDN? [duplicate]
- Register scripts located in child theme?
- How to add GET variable after script url?
- Generating a static page from a script
- Refused to execute as script because “X-Content-Type: nosniff” was given and its Content-Type is not a script MIME type
- Disable load scripts and styles not working
- Socialite not displaying icons [closed]
- Script dependencies generates different outputs
- How do I make it so that wp-scripts builds on plugin activation
- What is your best practice to execute one-time scripts?
- How do I get the $handle for all enqueued scripts?
- How can I get a list of all enqueued scripts and styles?
- How to properly dequeue scripts and styles in child theme?
- Conditionally enqueue a widget’s script/stylesheet in HEAD (only when present on page!)
- What are the benefits of using wp_enqueue_script?
- How can I create a bash install script for my WordPress sites setup (WP+plugins+theme)?
- Correct Method to run scripts with dependencies without enqueue?
- dynamically add scripts to WP_Widget widget() method
- Load plugin scripts and styles only on plugin page
- Get list of scripts / styles and show file which enqueued them
- How to prevent wordpress from loading old versions of jquery in wp_head();?
- Is it possible to change the attributes of a registered style or script before it fires?
- How to get a jQuery script to run on a page?
- Outputting Canonical Resource URLs Across a Multisite Network?
- Editing Source Code in WordPress
- How to load JQuery easing script in wordpress?
- Odd Script File Trying to be Loaded
- wp_register_script multiple identifiers?
- Listing registered scripts
- Some way to Flush or Overwrite all Imported Content in a Site for a Fresh Import – How?
- Shortest possible shell script to install WordPress on Nginx server?
- Including javascript for a shortcode
- Trigger a php file on every post or page if a condition is met
- How do I load custom scripts and styles for a page?
- How do I enqueue(or delay loading of) tags in individual page posts?
- Styles and Scripts, Selectively enqueue across entire site
- How to remove some external js files from source?
- Best way to create a user programatically
- Why Allow Script Commands in Comments?
- WordPress Script Loading/Unloading — wp_deregister_script(‘jquery’)
- How does WordPress create its database during installation?
- Is there any free (or cheap) software that can be used for testing WordPress functionality?
- Select2 in WordPress
- Unable to load stylesheets and scripts to plugin settings page
- How can I add my script to admin using script-loader.php?
- Disable unneeded scripts in a wordpress installation
- wp_enqueue_script with dependencies doesn’t work
- wp_enqueue_script adds only the first script
- Help with enqueing scripts in footer after init action
- Javascript code inside “” in core WordPress files .php
- How to properly add Bootstrap and JQuery Javascripts?
- How to add unique image class to WordPress
- How to load script-related styles automatically?
- How do you load WordPress from an external script when using MultiSite? [duplicate]
- Question about the way that wp_register_script works
- WordPress doesn’t Load JQuery Now? Do I need to enqueue JQuery also?
- Loading jQuery in the footer after removing jQuery migrate?
- Writing scripts using WordPress / WooCommerce classes?
- How to avoid loading same script twice?
- How to cancel `wp_print_scripts`?
- How do I enqueue a JavaScript in my footer via the functions.php file?
- wp_add_inline_script not adding when script_loader_tag filtered
- Retrieve URL of Script/Style and Dependencies
- My scripts-bundle.js file is getting sent to the browser as a stylesheet css file. Help!
- How can I load an inline script after the enqueued scripts in admin?
- Overwrite or Replace code in WP_Footer
- Add stylesheets and js to template files when shortcode is used
- WXR slicing script
- Insert a button on a page with random number generation
- Why won’t my scripts load?
- Change directory of javascript files
- Add class to comment form div when comment-reply button is clicked
- Correct check for any admin page with editor
- how to put a custom field value in variable
- Is there a way to list all the JavaScript scripts that are actually loaded by WordPress? Do we care?
- Scripts at the end of the page
- Gutenberg Block Development: Trying to add custom js script to npm start command by modifying webpack.config
- Understrap child theme JS not working in custom-javascript.js file
- Google Tag Manger – no-script Code Not Found
- List All Enqueued Scripts and Styles
- Repeating admin-ajax.php not found error in admin
- Styles and scripts inside template part
- wp_dequeue_style and wp_dequeue_script not working on server but does work on local xampp
- Custom tag being removed from text editor
- I can’t enqueue my scripts – They literally aren’t being added to my site
- How to load library scripts in admin from plugins in noConflict wrapper?
- php syntax : [ && ] between commands [closed]
- why quotes shown in WordPress?
- Add script into front from my plugin