Skip to content

Commit

Permalink
Fix the issue that cannot run in a pre-ES2016 environment.
Browse files Browse the repository at this point in the history
  • Loading branch information
overcat committed Mar 8, 2024
1 parent 80b7f29 commit 783c1d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Buffer } from 'buffer';

if (!(Buffer.alloc(1).subarray(0, 1) instanceof Buffer)) {
Buffer.prototype.subarray = function subarray(start, end) {
const result = Uint8Array.prototype.subarray.call(this, start, end);
Object.setPrototypeOf(result, Buffer.prototype);
return result;
};
}

export default Buffer;
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module.exports = function () {
};
config.plugins.push(
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer']
Buffer: [path.resolve(__dirname, 'buffer.js'), 'default'],
})
);
} else {
Expand Down

0 comments on commit 783c1d0

Please sign in to comment.