feat: polyfill Buffer & crypto

This commit is contained in:
Igor Randjelovic
2021-08-10 16:47:39 +02:00
parent 093b369b74
commit d262e1db79
2 changed files with 15 additions and 0 deletions

View File

@@ -22,10 +22,12 @@
"acorn": "^8.0.0",
"acorn-stage3": "^4.0.0",
"babel-loader": "^8.0.0",
"buffer": "^6.0.3",
"chalk": "^4.0.0",
"cli-highlight": "^2.0.0",
"commander": "^7.0.0",
"copy-webpack-plugin": "^9.0.0",
"crypto-browserify": "^3.12.0",
"css": "^3.0.0",
"css-loader": "^5.0.0",
"dotenv-webpack": "^7.0.0",

View File

@@ -2,6 +2,7 @@ import {
ContextExclusionPlugin,
DefinePlugin,
HotModuleReplacementPlugin,
ProvidePlugin,
} from 'webpack';
import Config from 'webpack-chain';
import { resolve } from 'path';
@@ -363,6 +364,18 @@ export default function (config: Config, env: IWebpackEnv = _env): Config {
},
]);
// polyfill things that don't exist in the NS runtimes
config.plugin('ProvidePlugin|Polyfills').use(ProvidePlugin, [
{
Buffer: [require.resolve('buffer/'), 'Buffer'],
},
]);
config.resolve.set('fallback', {
buffer: require.resolve('buffer/'),
crypto: require.resolve('crypto-browserify/'),
});
// enable DotEnv
applyDotEnvPlugin(config);