10

I am trying to build a module using the module-bundler ParcelJS. I would like this certain module to be import-friendly:

  • it should be import friendly (ES6)
  • It should be require friendly (Node)
  • It should be script-src friendly (Browser)
  • It should support the UMD convention...

I tried the following:

TestClass.js

export class TestClass {
  constructor(msg) {
    this.msg = msg;
    this.init();
  }
  init() {
    document.body.insertAdjacentHTML('afterbegin', `
    <div class="message">${this.msg}</div>`);
  }
}

index.js (file that creates the bundle)

//import styling for TestClass
import styles from '../css/styles';

//import class TestClass library
import { TestClass } from './TestClass';

//export TestClass
export default TestClass;

Trying to create the universal bundle by running: parcel index.js --global TestClass

Is there someone who can give me more information/help on exporting modules using parceljs?

Verhulstd
  • 241
  • 2
  • 10

1 Answers1

-1

You can use:

parcel build index.js --global TestClass

Some CLI Options:

  • -d: choose directory
  • -o: output filename
  • --no-minify
  • --global <GlobalName>

If you want to watch and build at the time:

parcel watch build index.js --global TestClass
Mohammed Samir
  • 118
  • 1
  • 6