@alphabetabc/node-browserify-polyfill
v0.0.4
Published
> https://github.com/niksy/node-stdlib-browser > > https://gitee.com/mirrors_niksy/node-stdlib-browser
Downloads
4
Readme
node-browserify-polyfill
https://github.com/niksy/node-stdlib-browser
https://gitee.com/mirrors_niksy/node-stdlib-browser
why
- webpack 5 no longer polyfills Node.js core modules
- vite or rollup need some browserify polyfill
list
Here is a list of polyfills webpack has used before webpack 5
{
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
// console: require.resolve('console-browserify'),
// constants: require.resolve('constants-browserify'),
crypto: require.resolve('crypto-browserify'),
domain: require.resolve('domain-browser'),
events: require.resolve('events'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify/browser'),
path: require.resolve('path-browserify'),
punycode: require.resolve('punycode'),
process: require.resolve('process/browser'),
querystring: require.resolve('querystring-es3'),
stream: require.resolve('stream-browserify'),
string_decoder: require.resolve('string_decoder'),
sys: require.resolve('util'),
timers: require.resolve('timers-browserify'),
tty: require.resolve('tty-browserify'),
url: require.resolve('url'),
util: require.resolve('util'),
vm: require.resolve('vm-browserify'),
zlib: require.resolve('browserify-zlib'),
}
polyfills-browser
## webpack.config
const config = {
resolve: {
extensions: ['.tsx', '.ts', '.js'],
alias: {
'@Pages': path.resolve(__dirname, 'src/pages'),
},
fallback: {
// 如果用不到就置为 false
assert: require.resolve('assert'),
buffer: require.resolve('buffer'),
// console: require.resolve('console-browserify'),
// constants: require.resolve('constants-browserify'),
crypto: require.resolve('crypto-browserify'),
domain: require.resolve('domain-browser'),
events: require.resolve('events'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: require.resolve('os-browserify/browser'),
path: require.resolve('path-browserify'),
punycode: require.resolve('punycode'),
process: require.resolve('process/browser'),
querystring: require.resolve('querystring-es3'),
stream: require.resolve('stream-browserify'),
string_decoder: require.resolve('string_decoder'),
sys: require.resolve('util'),
timers: require.resolve('timers-browserify'),
tty: require.resolve('tty-browserify'),
url: require.resolve('url'),
util: require.resolve('util'),
vm: require.resolve('vm-browserify'),
zlib: require.resolve('browserify-zlib'),
},
},
};
vite
import { lib } from '@alphabetabc/node-browserify-polyfill';
const config = defineConfig({
root: root,
resolve: {
alias: {
'~antd': resolveNodemodules('antd'), // 解决antd样式报错
process: 'process/browser',
},
},
css: {
preprocessorOptions: {
less: {
javascriptEnabled: true,
math: 'always',
},
},
},
define: {
global: {},
process: lib.process,
stream: lib.stream,
zlib: lib.zlib,
util: lib.util,
},
});