-
-
Notifications
You must be signed in to change notification settings - Fork 245
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked browser builds, make default build compatible with both node…
… & browsers due to non-ideal browser field support
- Loading branch information
Showing
7 changed files
with
42 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export default typeof window !== 'undefined' && typeof document !== 'undefined'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const { createMacro, MacroError } = require('babel-plugin-macros'); | ||
const { addDefault } = require('@babel/helper-module-imports'); | ||
|
||
module.exports = createMacro(({ references, babel: { template } }) => { | ||
const usedReferences = Object.keys(references); | ||
|
||
if (usedReferences.length > 1 || usedReferences[0] !== 'default') { | ||
throw new MacroError( | ||
`${__filename} must be used as default import, instead you have used it as: ${usedReferences.join( | ||
', ', | ||
)}.`, | ||
); | ||
} | ||
|
||
const { name: insertedName } = addDefault( | ||
references.default[0], | ||
'./isBrowser', | ||
{ nameHint: 'isBrowser' }, | ||
); | ||
|
||
const enhancedIsBrowser = template(`process.env.BROWSER || ${insertedName}`, { | ||
placeholderPattern: false, | ||
}); | ||
|
||
references.default.forEach(isBrowser => { | ||
isBrowser.replaceWith(enhancedIsBrowser().expression); | ||
}); | ||
}); |