Skip to content

Commit

Permalink
Fixed missed minified builds; (#4805)
Browse files Browse the repository at this point in the history
* Fixed missed minified builds;
Refactored utils.js;
Refactored `utils.isStandardBrowserEnv()` as a `platform/browser` property;
Added builds size log;

* Replaced `rollup-plugin-filesize` with `rollup-plugin-bundle-size`;

Co-authored-by: Jay <jasonsaayman@gmail.com>
  • Loading branch information
DigitalBrainJS and jasonsaayman committed Aug 1, 2022
1 parent d17d9a6 commit cd8989a
Show file tree
Hide file tree
Showing 8 changed files with 254 additions and 95 deletions.
4 changes: 2 additions & 2 deletions lib/adapters/xhr.js
Expand Up @@ -58,7 +58,7 @@ export default function xhrAdapter(config) {
}
}

if (utils.isFormData(requestData) && utils.isStandardBrowserEnv()) {
if (utils.isFormData(requestData) && platform.isStandardBrowserEnv) {
requestHeaders.setContentType(false); // Let the browser set it
}

Expand Down Expand Up @@ -174,7 +174,7 @@ export default function xhrAdapter(config) {
// Add xsrf header
// This is only done if running in a standard browser environment.
// Specifically not if we're in a web worker, or react-native.
if (utils.isStandardBrowserEnv()) {
if (platform.isStandardBrowserEnv) {
// Add xsrf header
const xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath))
&& config.xsrfCookieName && cookies.read(config.xsrfCookieName);
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/cookies.js
@@ -1,8 +1,9 @@
'use strict';

import utils from './../utils.js';
import platform from '../platform/index.js';

export default utils.isStandardBrowserEnv() ?
export default platform.isStandardBrowserEnv ?

// Standard browser envs support document.cookie
(function standardBrowserEnv() {
Expand Down
3 changes: 2 additions & 1 deletion lib/helpers/isURLSameOrigin.js
@@ -1,8 +1,9 @@
'use strict';

import utils from './../utils.js';
import platform from '../platform/index.js';

export default utils.isStandardBrowserEnv() ?
export default platform.isStandardBrowserEnv ?

// Standard browser envs have full support of the APIs needed to test
// whether the request URL is of the same origin as current location.
Expand Down
31 changes: 31 additions & 0 deletions lib/platform/browser/index.js
@@ -1,12 +1,43 @@
import URLSearchParams from './classes/URLSearchParams.js'
import FormData from './classes/FormData.js'

/**
* Determine if we're running in a standard browser environment
*
* This allows axios to run in a web worker, and react-native.
* Both environments support XMLHttpRequest, but not fully standard globals.
*
* web workers:
* typeof window -> undefined
* typeof document -> undefined
*
* react-native:
* navigator.product -> 'ReactNative'
* nativescript
* navigator.product -> 'NativeScript' or 'NS'
*
* @returns {boolean}
*/
const isStandardBrowserEnv = (() => {
let product;
if (typeof navigator !== 'undefined' && (
(product = navigator.product) === 'ReactNative' ||
product === 'NativeScript' ||
product === 'NS')
) {
return false;
}

return typeof window !== 'undefined' && typeof document !== 'undefined';
})();

export default {
isBrowser: true,
classes: {
URLSearchParams,
FormData,
Blob
},
isStandardBrowserEnv,
protocols: ['http', 'https', 'file', 'blob', 'url', 'data']
};

0 comments on commit cd8989a

Please sign in to comment.