openbibleinfo / Bible-Passage-Reference-Parser

Coffeescript to identify and understand Bible references like "John 3:16."
221 stars 64 forks source link

import as a ES2015 module #46

Open john916zhang opened 4 years ago

john916zhang commented 4 years ago

Thanks for developing this wonderful library. Just a quick question. How to import this library as a ES2015 module?

var bcv_parser = require("bible-passage-reference-parser/js/en_bcv_parser").bcv_parser;

I'd like to use ES2015'simport instead of CommonJS's require.

RyanQuey commented 3 years ago

You can just do e.g.,

import { bcv_parser as eng_bcv_parser } from "bible-passage-reference-parser/js/en_bcv_parser"
cco3 commented 1 year ago

This is becoming more brittle in some environments:

'bcv_parser' is not exported by node_modules/bible-passage-reference-parser/js/en_bcv_parser.js
openbibleinfo commented 1 year ago

@cco3 It looks like the best approach to maintain both the old and the new import styles is to create a new directory with files that use the new style and add a statement to the package.json file. Does that sound like the right approach?

cco3 commented 1 year ago

Yes, basically just use new-style imports and run it through something like vite or rollup to create outputs in a dist directory which are referenced in package.json.