0

I am trying to copy a single file from the src location to the "www" output folder. I then want to incorporate this into the build process so that after all the core build scripts are run, it runs my command.

I am following the examples in the App Build Scripts for Ionic. Basically I have:

Added a new config file with my command (as per this example): config\webpack_rj.config.js

module.exports = {
    copyIndexContent: {
        src: ['{{SRC}}/web.config'],
        dest: '{{WWW}}'
    }
}

In my package.json I have added:

"config": {
  "pwa_copy_webconfig": "./config/webpack_rj.config.js"
},

This is the part I do not understand - how to actually run it when I run the normal build process.

I have tried added an additional "scripts" entry in the package.json:

"build": "ionic-app-scripts build ./config/webpack_rj.config.js",

However this did not work. So how can I invoke copyIndexContent or pwa_copy_webconfig from the build process?

RobC
  • 22,977
  • 20
  • 73
  • 80
Rodney
  • 5,417
  • 7
  • 54
  • 98

1 Answers1

2

You are trying to add a new step to the build process instead of extending copy. This is not possible unless you make custom changes to the app scripts module to take the pwa_copy_webconfig command from the config.

A common way is to extend the existing config file. You can extend the copy.config.js in your webpack_rj.config.js file.

const copyConfig = require('path_to_default_copy_config');
copyConfig.copyIndexContent.src.push('{{SRC}}/web.config');

In package.json add:

"config": {
  "ionic_copy": "./config/webpack_rj.config.js"
},

Credit to Raj's answer here for a different app script configuration.

RobC
  • 22,977
  • 20
  • 73
  • 80
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
  • Excellent, that's exactly what I needed and a great solution, thanks – Rodney Oct 12 '17 at 17:03
  • One question - where does the name of the config come in -e.g. "ionic_copy". If I change this to something else it does not execute. How is it related to the build process? – Rodney Oct 12 '17 at 17:13
  • it's the commands provided in the script to override specific configuration files. Check the section on override configuration files in the github readme – Suraj Rao Oct 12 '17 at 17:17
  • https://github.com/ionic-team/ionic-app-scripts/blob/master/README.md#overriding-config-files – Suraj Rao Oct 12 '17 at 17:19
  • FYI, here's the value I used for the somewhat vague string `path_to_default_copy_config`: `../node_modules/@ionic/app-scripts/config/copy.config.js` – Matt Dodge Jan 30 '19 at 05:41