diff --git a/.changeset/curly-shrimps-wait.md b/.changeset/curly-shrimps-wait.md new file mode 100644 index 00000000000..3e8709444cf --- /dev/null +++ b/.changeset/curly-shrimps-wait.md @@ -0,0 +1,5 @@ +--- +@firebase/storage: minor +--- + +Add NodeJS support to Cloud Storage for Firebase. This release changes the `main` field in package.json to point to a Node specific build. If you are building a bundle for borwser usage, please make sure that your bundler uses the `browser` field (the default). diff --git a/packages/storage/package.json b/packages/storage/package.json index 5a24c090035..6170e36003c 100644 --- a/packages/storage/package.json +++ b/packages/storage/package.json @@ -3,10 +3,10 @@ "version": "0.5.6", "description": "", "author": "Firebase (https://firebase.google.com/)", - "main": "dist/index.cjs.js", - "module": "dist/index.esm.js", - "browser": "dist/index.esm.js", - "esm2017": "dist/index.esm2017.js", + "main": "dist/index.node.cjs.js", + "module": "dist/index.browser.esm.js", + "browser": "dist/index.browser.esm.js", + "esm2017": "dist/index.browser.esm2017.js", "files": [ "dist", "exp/dist" @@ -66,4 +66,4 @@ "url": "https://github.com/firebase/firebase-js-sdk/issues" }, "typings": "dist/index.d.ts" -} \ No newline at end of file +} diff --git a/packages/storage/rollup.config.js b/packages/storage/rollup.config.js index 15f306a50d8..d0688d3e9c6 100644 --- a/packages/storage/rollup.config.js +++ b/packages/storage/rollup.config.js @@ -26,6 +26,9 @@ const { generateAliasConfig } = require('./rollup.shared'); const deps = Object.keys( Object.assign({}, pkg.peerDependencies, pkg.dependencies) ); + +const nodeDeps = [...deps, 'util']; + /** * ES5 Builds */ @@ -39,10 +42,7 @@ const es5BuildPlugins = [ const es5Builds = [ { input: './index.ts', - output: [ - { file: pkg.main, format: 'cjs', sourcemap: true }, - { file: pkg.module, format: 'es', sourcemap: true } - ], + output: { file: pkg.module, format: 'es', sourcemap: true }, plugins: [alias(generateAliasConfig('browser')), ...es5BuildPlugins], external: id => deps.some(dep => id === dep || id.startsWith(`${dep}/`)), treeshake: { @@ -67,6 +67,22 @@ const es2017BuildPlugins = [ ]; const es2017Builds = [ + // Node + { + input: './index.ts', + output: { + file: pkg.main, + format: 'cjs', + sourcemap: true + }, + plugins: [alias(generateAliasConfig('node')), ...es2017BuildPlugins], + external: id => + nodeDeps.some(dep => id === dep || id.startsWith(`${dep}/`)), + treeshake: { + moduleSideEffects: false + } + }, + // Browser { input: './index.ts', output: {