Share modules between apps - architecture

As I am running out of time to solve this, I’m taking the shorter path now. I think I got it working with symlinks as follows:

  1. Moved out an exemplary shared module to some shared folder
  2. Created a symlink (windows, admin CMD required): cd …\src\modules && mklink /D shared …\ …\ …\ …\SharedModules\shared (hint: be aware that the forum modifies the target path somehow strangely)
  3. Add ./config/watch.config.js:
const watchConfig = require('@ionic/app-scripts/config/watch.config');

// add symlinked paths manually to enforce them being watched - even though they are in src/ folder they will otherwise be ignored
watchConfig.srcFiles.paths.push('{{SRC}}/modules/shared/**/*.(ts|html|s(c|a)ss)');

module.exports = watchConfig;
  1. Add ./config/webpack.config.js:
const webpackConfig = require('@ionic/app-scripts/config/webpack.config');
// When using symlinks for modules this must be set to FALSE, otherwise compile issues will be shown
// yes this sounds counter intuitive...
webpackConfig.dev.resolve.symlinks = false;
webpackConfig.prod.resolve.symlinks = false;

module.exports = webpackConfig;
  1. Add to package.json to use our new config files
  "config": {
    "ionic_watch": "config/watch.config.js",
    "ionic_webpack": "config/webpack.config.js"
  }

This seems to work, including ionic serve, live reload and production build.
If somebody else has some spare time and can go on with my results to investigate better options, I would be glad…
All I need now is some kind of setup script which initializes the symlinks after checkout on all platforms.

edit: does somebody know a cross-platform solution for adding symlinks, e.g. via npm “postinstall” script which does not require admin privileges on windows?

1 Like