summaryrefslogtreecommitdiffhomepage
path: root/packages/browser/rollup.config.js
diff options
context:
space:
mode:
authorMatthew Miller <matthew@millerti.me>2021-04-13 09:11:19 -0700
committerMatthew Miller <matthew@millerti.me>2021-04-13 09:11:19 -0700
commit59678bff70b388f9237b05748a6cad3d65c3c20f (patch)
tree0cd0ded462003fb69ce2231da6eb181c7dc993b9 /packages/browser/rollup.config.js
parente6557e2c1afaf357098972b9850883ab1a554fd3 (diff)
parent8d48bfdc574ec6f616f3264c767a16f4fcf2086f (diff)
Merge branch 'master' into fix/issue-111-cert-hExtV-parse-error
Diffstat (limited to 'packages/browser/rollup.config.js')
-rw-r--r--packages/browser/rollup.config.js115
1 files changed, 115 insertions, 0 deletions
diff --git a/packages/browser/rollup.config.js b/packages/browser/rollup.config.js
new file mode 100644
index 0000000..3428748
--- /dev/null
+++ b/packages/browser/rollup.config.js
@@ -0,0 +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';
+
+/**
+ * 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;
+ },
+ };
+};
+
+/**
+ * Re-enable version injection when this gets resolved:
+ *
+ * https://github.com/djhouseknecht/rollup-plugin-version-injector/issues/22
+ *
+ * To avoid a repeat of the first half of this:
+ *
+ * https://github.com/MasterKale/SimpleWebAuthn/issues/56
+ */
+// const swanVersionInjector = 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 configuration to generate the following:
+ * - ES2018 bundle
+ * - ES5 bundle
+ * - Type declarations
+ */
+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(),
+ // swanVersionInjector,
+ ],
+ },
+ {
+ 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(),
+ // swanVersionInjector,
+ ],
+ 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(),
+ // swanVersionInjector,
+ ],
+ },
+];