Custom Watch Task on Node Module Changes


#1

I have a custom watch config used to listen for an npm linked module that will have changes persist when you make changes to the main folder.

watch.config.js

var watch = require('@ionic/app-scripts/dist/watch');
var copy = require('@ionic/app-scripts/dist/copy');
var copyConfig = require('./copy.config');

// this is a custom dictionary to make it easy to extend/override
// provide a name for an entry, it can be anything such as 'srcFiles' or 'copyConfig'
// then provide an object with the paths, options, and callback fields populated per the Chokidar docs
// https://www.npmjs.com/package/chokidar

module.exports = {
    srcFiles: {
        paths: [
            '{{SRC}}/**/*.(ts|html|s(c|a)ss)',
        ],
        options: {
            ignored: [
                '{{SRC}}/**/*.spec.ts',
                '{{SRC}}/**/*.e2e.ts',
                '**/*.DS_Store',
                '{{SRC}}/index.html'
            ]
        },
        callback: watch.buildUpdate
    },
    libFiles: {
        paths: [
            '{{ROOT}}/node_modules/@nx-ionic/**/*.(ts|html|s(c|a)ss)'
        ],
        callback: watch.buildUpdate
    },
    copyConfig: copy.copyConfigToWatchConfig()
};

I have also added the watch script to the correct config section of the package.json:

  "config": {
      "ionic_watch": "config/watch.config.js",
      "ionic_copy": "config/copy.config.js",
      "ionic_webpack": "config/webpack.config.js"
  },

The issue that I am facing is that when I make changes to the linked module, the watch does in fact fire and it says the app is building, but the main.js never actually rebuilds and always reflects the old changes.

If I make changes inside the ionic app, the app will rebuild with those changes, but will never take any new changes from node_modules, unless I completely re-serve the app.

On the latest of everything and using ionic-app-scripts.

Has anyone faced this issue, know where or how to accomplish what I need? I’ve dug through the build scripts and tried altering them to always form a full build, but that gridlocks the process. I’ve also looked at modifying the webpack config, but there does not seem to be any publicly documented configurations for external packages.

Thanks!


#2

did you find a solution to your problem?
Thanks


#3

I’ve got the same issue. The custom watch fires, logs a debug line to console, but doesn’t build.


#4

I’ve got it working, using some debug statements. Hope it helps:

var watch = require('@ionic/app-scripts/dist/watch');
var copy = require('@ionic/app-scripts/dist/copy');
//var copyConfig = require('./copy.config');

// this is a custom dictionary to make it easy to extend/override
// provide a name for an entry, it can be anything such as 'srcFiles' or 'copyConfig'
// then provide an object with the paths, options, and callback fields populated per the Chokidar docs
// https://www.npmjs.com/package/chokidar

module.exports = {
  srcFiles: {
    paths: ['{{SRC}}/**/*.(ts|html|s(c|a)ss)'],
    options: { ignored: ['{{SRC}}/**/*.spec.ts', '{{SRC}}/**/*.e2e.ts', '**/*.DS_Store', '{{SRC}}/index.html'] },
    callback: function(event, filePath, context) {
        return new Promise(resolve => {
            console.log("DEBUG1");
            watch.buildUpdate(event, filePath, context).then(function() {
                console.log("DEBUG2");
                resolve();
            });
        });
    }
  },
  copyConfig: copy.copyConfigToWatchConfig()
};