Parceljs build UMD
Asked Answered
M

1

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?

Mold answered 23/5, 2018 at 14:36 Comment(0)
D
-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
Declamatory answered 1/2, 2021 at 7:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.