summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorakanass <akanass@icloud.com>2021-04-06 14:38:11 +0200
committerakanass <akanass@icloud.com>2021-04-06 14:38:11 +0200
commit60eafde07708db6866b9fdadfa7070f567db6633 (patch)
treee1ccd7cf8ba9e6aa01541876b7edfb87784197f7
parentfe2eeebd05b6a74040741dafc1ba1616617893ff (diff)
optimized build process with fewer files and all desired versions
-rw-r--r--packages/browser/package.json9
-rw-r--r--packages/browser/rollup.config.es5.js41
-rw-r--r--packages/browser/rollup.config.js130
-rw-r--r--packages/browser/tsconfig.es5.json1
4 files changed, 115 insertions, 66 deletions
diff --git a/packages/browser/package.json b/packages/browser/package.json
index d9e8b55..9dda13e 100644
--- a/packages/browser/package.json
+++ b/packages/browser/package.json
@@ -2,8 +2,8 @@
"name": "@simplewebauthn/browser",
"version": "2.1.0",
"description": "SimpleWebAuthn for Browsers",
- "main": "dist/bundles/index.es2018.js",
- "browser": "dist/bundles/index.es5.js",
+ "main": "dist/es2018/index.js",
+ "browser": "dist/es5/index.js",
"types": "dist/types/index.d.ts",
"author": "Matthew Miller <matthew@millerti.me>",
"license": "MIT",
@@ -17,9 +17,8 @@
"access": "public"
},
"scripts": {
- "build": "npm-run-all -l clean -p build:es2018 build:es5",
- "build:es2018": "rollup -c",
- "build:es5": "rollup -c rollup.config.es5.js",
+ "build": "npm-run-all -l clean -s build:bundles",
+ "build:bundles": "rollup -c",
"clean": "rimraf dist",
"test": "jest",
"test:watch": "jest --watch",
diff --git a/packages/browser/rollup.config.es5.js b/packages/browser/rollup.config.es5.js
deleted file mode 100644
index 92d10c1..0000000
--- a/packages/browser/rollup.config.es5.js
+++ /dev/null
@@ -1,41 +0,0 @@
-import typescript from '@rollup/plugin-typescript';
-import commonjs from '@rollup/plugin-commonjs';
-import nodeResolve from '@rollup/plugin-node-resolve';
-import { terser } from 'rollup-plugin-terser';
-import versionInjector from 'rollup-plugin-version-injector';
-
-export default {
- input: 'src/index.ts',
- output: [
- {
- dir: 'dist',
- format: 'cjs',
- entryFileNames: 'bundles/[name].es5.js',
- exports: 'auto',
- },
- {
- dir: 'dist',
- format: 'umd',
- name: 'SimpleWebAuthnBrowser',
- entryFileNames: 'bundles/[name].umd.min.js',
- plugins: [terser()],
- globals: {
- tslib: 'tslib',
- },
- },
- ],
- plugins: [
- typescript({ tsconfig: './tsconfig.es5.json' }),
- commonjs({ extensions: ['.ts'] }),
- nodeResolve(),
- versionInjector({
- injectInComments: {
- fileRegexp: /\.(js)$/,
- // [@simplewebauthn/browser] Version: 2.1.0 - Saturday, February 6th, 2021, 4:10:31 PM
- tag: '[@simplewebauthn/browser] Version: {version} - {date}',
- dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT',
- },
- }),
- ],
- external: ['tslib'],
-};
diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js
index cb701c1..6d2914f 100644
--- a/packages/browser/rollup.config.js
+++ b/packages/browser/rollup.config.js
@@ -1,25 +1,115 @@
import typescript from '@rollup/plugin-typescript';
+import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
+import { terser } from 'rollup-plugin-terser';
import versionInjector from 'rollup-plugin-version-injector';
-export default {
- input: 'src/index.ts',
- output: {
- dir: 'dist',
- format: 'esm',
- entryFileNames: 'bundles/[name].es2018.js',
- preferConst: true,
- },
- plugins: [
- typescript({ tsconfig: './tsconfig.json' }),
- nodeResolve(),
- versionInjector({
- injectInComments: {
- fileRegexp: /\.(js)$/,
- // [@simplewebauthn/browser] Version: 2.1.0 - Saturday, February 6th, 2021, 4:10:31 PM
- tag: '[@simplewebauthn/browser] Version: {version} - {date}',
- dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT',
- },
- }),
- ],
+/**
+ * Rollup plugin to clean `tslib` comment in `UMD` bundle targeting `ES5`
+ */
+const cleanTslibCommentInUMDBundleTargetingES5 = () => {
+ return {
+ name: 'cleanTslibCommentInUMDBundleTargetingES5',
+ renderChunk: async code => {
+ const comment = `
+/*! *****************************************************************************
+\tCopyright (c) Microsoft Corporation.
+
+\tPermission to use, copy, modify, and/or distribute this software for any
+\tpurpose with or without fee is hereby granted.
+
+\tTHE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
+\tREGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+\tAND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
+\tINDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
+\tLOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+\tOTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+\tPERFORMANCE OF THIS SOFTWARE.
+\t***************************************************************************** */
+`;
+ return code.indexOf(comment) > -1 ? code.replace(comment, '') : null;
+ },
+ };
};
+
+/**
+ * Rollup configuration to generate all bundles in ES2018, ES5 and types
+ */
+export default [
+ {
+ input: 'src/index.ts',
+ output: [
+ {
+ dir: 'dist',
+ format: 'esm',
+ entryFileNames: 'es2018/[name].js',
+ preferConst: true,
+ },
+ {
+ dir: 'dist',
+ format: 'umd',
+ name: 'SimpleWebAuthnBrowser',
+ entryFileNames: 'es2018/[name].umd.min.js',
+ plugins: [terser()],
+ },
+ ],
+ plugins: [
+ typescript({ tsconfig: './tsconfig.json' }),
+ nodeResolve(),
+ versionInjector({
+ injectInComments: {
+ fileRegexp: /\.(js)$/,
+ // [@simplewebauthn/browser] Version: 2.1.0 - Saturday, February 6th, 2021, 4:10:31 PM
+ tag: '[@simplewebauthn/browser] Version: {version} - {date}',
+ dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT',
+ },
+ }),
+ ],
+ },
+ {
+ input: 'src/index.ts',
+ output: {
+ dir: 'dist',
+ format: 'cjs',
+ entryFileNames: 'es5/[name].js',
+ exports: 'auto',
+ },
+ plugins: [
+ typescript({ tsconfig: './tsconfig.es5.json' }),
+ commonjs({ extensions: ['.ts'] }),
+ nodeResolve(),
+ versionInjector({
+ injectInComments: {
+ fileRegexp: /\.(js)$/,
+ // [@simplewebauthn/browser] Version: 2.1.0 - Saturday, February 6th, 2021, 4:10:31 PM
+ tag: '[@simplewebauthn/browser] Version: {version} - {date}',
+ dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT',
+ },
+ }),
+ ],
+ external: ['tslib'],
+ },
+ {
+ input: 'src/index.ts',
+ output: {
+ dir: 'dist',
+ format: 'umd',
+ name: 'SimpleWebAuthnBrowser',
+ entryFileNames: 'es5/[name].umd.min.js',
+ plugins: [terser(), cleanTslibCommentInUMDBundleTargetingES5()],
+ },
+ plugins: [
+ typescript({ tsconfig: './tsconfig.es5.json' }),
+ commonjs({ extensions: ['.ts'] }),
+ nodeResolve(),
+ versionInjector({
+ injectInComments: {
+ fileRegexp: /\.(js)$/,
+ // [@simplewebauthn/browser] Version: 2.1.0 - Saturday, February 6th, 2021, 4:10:31 PM
+ tag: '[@simplewebauthn/browser] Version: {version} - {date}',
+ dateFormat: 'dddd, mmmm dS, yyyy, h:MM:ss TT',
+ },
+ }),
+ ],
+ },
+];
diff --git a/packages/browser/tsconfig.es5.json b/packages/browser/tsconfig.es5.json
index e0bc7b8..3d1a328 100644
--- a/packages/browser/tsconfig.es5.json
+++ b/packages/browser/tsconfig.es5.json
@@ -10,6 +10,7 @@
],
"baseUrl": "./src",
"declaration": false,
+ "declarationDir": null,
"declarationMap": false,
"downlevelIteration": true,
"removeComments": true,