Sunday, October 9, 2016

Migrating to Ionic 2 RC 0 - CommonJS files

After migrating my app to Ionic 2 RC 0, I was able to typescript-compile my app, but the bundling failed with
bundle dev failed:  Module .../node_modules/log4javascript/log4javascript.js does not export getRootLogger 
Finally, after some googling, I found out, that I had to define the so-called custom named exports of log4javascript by myself:
  1. Copy rollup.config.js from node_modules/@ionic/app-scripts/config into my own config directory.
  2. Change my package.json according to the documentation:
    "config": {
      "ionic_rollup": "./config/rollup.config.js"
    },
    
  3. Add configuration for commonjs plugin in rollup.config.js:
    plugins: [
      commonjs({
        include: [
          'node_modules/log4javascript/**',
        ],
        namedExports: {
          'node_modules/log4javascript/log4javascript.js': [
            'Appender', 'BrowserConsoleAppender', 'getLogger', 'getRootLogger', 'Level', 'LoggingEvent', 'logLog', 'PatternLayout'
          ]
        }
      }),
      ...
    ]
    
As you can see, I had to define every single thing I used from log4javascript. Not beautiful, but it works.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.