-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
42 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
// Get original, non-ESM code | ||
const originalCode = fs.readFileSync( | ||
path.resolve(__dirname, '../', 'index.js'), | ||
{ encoding: 'utf8' } | ||
) | ||
|
||
// Transform CommonJS/universal code into ESM code. | ||
// We provide an Object as thisArg and tell the script to bind | ||
// to it (even if run in CommonJS env) through a special property. | ||
// Then we export the polyfill now bound to the provided Object. | ||
const esmCode = `const esmMock = { __ESM_MOCK__: true }; | ||
(function() { | ||
${originalCode} | ||
}).call(esmMock); | ||
const { SmoothscrollAnchorPolyfill } = esmMock; | ||
const { destroy, polyfill } = SmoothscrollAnchorPolyfill; | ||
export { destroy, polyfill }; | ||
export default SmoothscrollAnchorPolyfill;` | ||
|
||
// Write ESM code to directory "dist" | ||
fs.writeFileSync(path.resolve(__dirname, '../', 'dist', 'index.mjs'), esmCode, 'utf8') |