openbibleinfo / Bible-Passage-Reference-Parser

Coffeescript to identify and understand Bible references like "John 3:16."

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

import as a ES2015 module

john916zhang opened this issue · comments

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.

You can just do e.g.,

import { bcv_parser as eng_bcv_parser } from "bible-passage-reference-parser/js/en_bcv_parser"

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

@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?

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.