diff --git a/README.md b/README.md index 907697f..9064928 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ npm install bigint-crypto-utils NPM installation defaults to the ES6 module for browsers and the CJS one for Node.js. -For web browsers, you can also directly download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.js) or the [ES6 bundle module](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.min.mod.js) from GitHub. +For web browsers, you can also directly download the [IIFE bundle](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.iife.js) or the [ES6 bundle module](https://raw.githubusercontent.com/juanelas/bigint-crypto-utils/master/lib/index.browser.bundle.mod.js) from GitHub. ## Usage examples @@ -29,11 +29,12 @@ Import your module as : const bigintCryptoUtils = require('bigint-crypto-utils') ... // your code here ``` - - JavaScript native project + - JavaScript native or TypeScript project ```javascript import * as bigintCryptoUtils from 'bigint-crypto-utils' ... // your code here ``` + > BigInt is [ES-2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you should set `lib` (and probably also `target` and `module`) to `esnext` in `tsconfig.json`. - JavaScript native browser ES6 mod ```html - + + ... + + + + ... + + ``` - - TypeScript - ```typescript - import * as bigintCryptoUtils from 'bigint-crypto-utils' - ... // your code here - ``` - > BigInt is [ES-2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you should set `lib` (and probably also `target` and `module`) to `esnext` in `tsconfig.json`. And you could use it like in the following: diff --git a/build/build.docs.js b/build/build.docs.js index 09264e5..fccc866 100644 --- a/build/build.docs.js +++ b/build/build.docs.js @@ -8,7 +8,7 @@ const pkgJson = require('../package.json') const rootDir = path.join(__dirname, '..') const template = path.join(rootDir, pkgJson.directories.src, 'doc', 'readme-template.md') -const input = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js') +const input = path.join(rootDir, pkgJson.browser) const source = fs.readFileSync(input, { encoding: 'UTF-8' }).replace(/([0-9]+)n([,\s\n)])/g, '$1$2') const options = { diff --git a/build/build.dts.js b/build/build.dts.js index b1ea3dc..bedea02 100644 --- a/build/build.dts.js +++ b/build/build.dts.js @@ -4,7 +4,7 @@ const path = require('path') const pkgJson = require('../package.json') const rootDir = path.join(__dirname, '..') -const jsFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js') +const jsFile = path.join(rootDir, pkgJson.browser) const dtsFile = path.join(rootDir, pkgJson.types) const compilerOptions = { diff --git a/build/rollup.config.js b/build/rollup.config.js index ae7cd52..df23f2d 100644 --- a/build/rollup.config.js +++ b/build/rollup.config.js @@ -25,38 +25,17 @@ const pkgCamelisedName = camelise(pkgName) const input = path.join(srcDir, 'js', 'index.js') module.exports = [ - { // ESM native module + { // Browser input: input, output: [ { file: path.join(rootDir, pkgJson.browser), - format: 'esm' - } - ], - plugins: [ - replace({ - 'process.browser': true - }) - ], - external: ['bigint-mod-arith'] - }, - { // Browser bundles - input: input, - output: [ - { - file: path.join(dstDir, 'index.browser.bundle.js'), - format: 'iife', - name: pkgCamelisedName, - plugins: [ - terser() - ] + format: 'es' }, { - file: path.join(dstDir, 'index.browser.bundle.min.mod.js'), - format: 'es', - plugins: [ - terser() - ] + file: path.join(dstDir, 'index.browser.bundle.iife.js'), + format: 'iife', + name: pkgCamelisedName }, { file: path.join(dstDir, 'index.browser.bundle.mod.js'), @@ -69,20 +48,26 @@ module.exports = [ }), resolve({ browser: true + // ignore: ['index.browser.mod.js'] + }), + terser({ + exclude: ['index.browser.mod.js'] }) ] }, { // Node input: input, - plugins: [ - replace({ - 'process.browser': false - }) - ], output: { file: path.join(dstDir, 'index.node.js'), format: 'cjs' }, - external: ['bigint-mod-arith'] + plugins: [ + replace({ + 'process.browser': false + }), + resolve({ + browser: true + }) + ] } ] diff --git a/build/rollup.tests.config.js b/build/rollup.tests.config.js index 3fc0b03..b5da420 100644 --- a/build/rollup.tests.config.js +++ b/build/rollup.tests.config.js @@ -21,7 +21,7 @@ const dstDir = path.join(rootDir, pkgJson.directories.test, 'browser') const dstFileName = path.join(dstDir, 'index.html') const template = fs.readFileSync(templatePath, 'utf-8') -const bundleFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.min.mod.js') +const bundleFile = path.join(rootDir, pkgJson.directories.lib, 'index.browser.bundle.mod.js') const testsJs = ` - + + ... + + + + ... + + ``` - - TypeScript - ```typescript - import * as bigintCryptoUtils from 'bigint-crypto-utils' - ... // your code here - ``` - > BigInt is [ES-2020](https://tc39.es/ecma262/#sec-bigint-objects). In order to use it with TypeScript you should set `lib` (and probably also `target` and `module`) to `esnext` in `tsconfig.json`. And you could use it like in the following: diff --git a/test/browser/index.html b/test/browser/index.html index d3783b0..140cb87 100644 --- a/test/browser/index.html +++ b/test/browser/index.html @@ -13,7 +13,7 @@ +