Skip to content

Commit

Permalink
Merge pull request #701 from benmccann/process-browser
Browse files Browse the repository at this point in the history
Remove the use of process.browser
  • Loading branch information
pubkey authored Aug 2, 2021
2 parents b04c0ee + 7294895 commit 593deb4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { terser } from 'rollup-plugin-terser';

export default {
input: './dist/es/index.js',
input: './dist/esbrowser/index.js',
output: {
sourcemap: true,
format: 'iife',
Expand Down
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "A BroadcastChannel that works in New Browsers, Old Browsers, WebWorkers and NodeJs",
"exports": {
"node": {
"import": "./dist/es/index.js",
"import": "./dist/esnode/index.js",
"default": "./dist/es5node/index.js"
},
"browser": {
"import": "./dist/esbrowser/index.js",
"default": "./dist/lib/index.es5.js"
},
"./package.json": "./package.json"
Expand Down Expand Up @@ -35,7 +36,7 @@
"url": "https://github.com/pubkey/broadcast-channel/issues"
},
"main": "./dist/es5node/index.js",
"module": "./dist/es/index.js",
"module": "./dist/esnode/index.js",
"browser": "./dist/lib/index.es5.js",
"sideEffects": false,
"types": "./types/index.d.ts",
Expand All @@ -55,7 +56,8 @@
"size:rollup": "npm run build && rollup --config ./config/rollup.config.js && echo \"Build-Size Rollup (minified+gzip):\" && gzip-size --raw ./test_tmp/rollup.bundle.js",
"lint": "eslint src test config",
"clear": "rimraf -rf ./dist && rimraf -rf ./gen",
"build:es6": "rimraf -rf dist/es && cross-env NODE_ENV=es6 babel src --out-dir dist/es",
"build:es6node": "rimraf -rf dist/esnode && cross-env NODE_ENV=es6 babel src --out-dir dist/esnode",
"build:es6browser": "rimraf -rf dist/esbrowser && cross-env NODE_ENV=es6 babel src --out-dir dist/esbrowser && grep -rl NodeMethod dist/esbrowser/ | xargs sed -i 's/.*NodeMethod.*//'",
"build:es5node": "cross-env NODE_ENV=es5 babel src --out-dir dist/es5node",
"build:es5browser": "cross-env NODE_ENV=es5 babel src --out-dir dist/lib && grep -rl NodeMethod dist/lib/ | xargs sed -i 's/.*NodeMethod.*//'",
"build:test": "cross-env NODE_ENV=es5 babel test --out-dir test_tmp",
Expand All @@ -66,7 +68,7 @@
"build:leader-iframe": "browserify test_tmp/scripts/leader-iframe.js > docs/leader-iframe.js",
"build:lib-browser": "browserify dist/lib/browserify.index.js > dist/lib/browser.js",
"build:lib-browser:min": "uglifyjs --compress --mangle --output dist/lib/browser.min.js -- dist/lib/browser.js",
"build": "npm run clear && concurrently \"npm run build:es6\" \"npm run build:es5node\" \"npm run build:es5browser\" \"npm run build:test\" && concurrently \"npm run build:index\" \"npm run build:browser\" \"npm run build:worker\" \"npm run build:iframe\" \"npm run build:leader-iframe\" && npm run build:lib-browser && npm run build:lib-browser:min",
"build": "npm run clear && concurrently \"npm run build:es6node\" \"npm run build:es6browser\" \"npm run build:es5node\" \"npm run build:es5browser\" \"npm run build:test\" && concurrently \"npm run build:index\" \"npm run build:browser\" \"npm run build:worker\" \"npm run build:iframe\" \"npm run build:leader-iframe\" && npm run build:lib-browser && npm run build:lib-browser:min",
"build:min": "uglifyjs --compress --mangle --output dist/lib/browserify.min.js -- dist/lib/browserify.index.js",
"docs:only": "http-server ./docs --silent",
"docs:serve": "npm run build && echo \"Open http://localhost:8080/\" && npm run docs:only"
Expand Down
10 changes: 2 additions & 8 deletions src/method-chooser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ const METHODS = [
export function chooseMethod(options) {
let chooseMethods = [].concat(options.methods, METHODS).filter(Boolean);

// process.browser check allows ES6 builds to be used on server or client. Bundlers like
// Browserify, Webpack, etc. define process.browser and can then dead code eliminate the unused
// import. However, we still use sed during build of es5/browser build to remove the import so
// that it's also removed from non-minified version
if (!process.browser) {
// the line below will be removed from es5/browser builds
chooseMethods.push(NodeMethod);
}
// the line below will be removed from es5/browser builds
chooseMethods.push(NodeMethod);

// directly chosen
if (options.type) {
Expand Down

0 comments on commit 593deb4

Please sign in to comment.