nashwaan / xml-js

Converter utility between XML text and Javascript object / JSON text.
MIT License
1.28k stars 182 forks source link

Browser bundling #54

Open vtrushin opened 6 years ago

vtrushin commented 6 years ago

From README:

Portable Code: Written purely in JavaScript which means it can be used in Node environment and browser environment (via bundlers like browserify/JSPM/Webpack).

It cannot be fully bundled for browsers because SAX requires Node's built-in packages 'Stream' and 'string_decoder' (https://github.com/isaacs/sax-js/blob/master/lib/sax.js#L233)

nashwaan commented 6 years ago

Thanks Vlad for this important feedback. I based my assumption on this line on sax project "Designed with node in mind, but should work fine in the browser or other CommonJS implementations." Any idea how to overcome this issue?

vtrushin commented 6 years ago

You're welcome. And thank you for this project. I use rollup for bundling, and have just found rollup-plugin-node-builtins to resove it. It replaces all node builtins. Maybe it's good solution, expect for Stream, that has really big implementation. But I think, that Stream's require can be ignored for replacing, because it's located in try/catch statement https://github.com/isaacs/sax-js/blob/master/lib/sax.js#L161-L166 and can work w/o it.

nashwaan commented 6 years ago

These are great findings to share! Thanks. I wonder if there is also a way I can require sax in a fully browser-compatible way so that I don't force the user to manually replace node built-ins.

eczn commented 5 years ago

emmm, how about React Native bundling? i have to decode xml on my React Native App, what should i do?

eczn commented 5 years ago

ooops, i found https://www.npmjs.com/package/react-native-xml2js to resolve my problem. 😂

hengkx commented 4 years ago

any progress?

james-innes commented 3 years ago

Please can this bulletin of the README be amended to reflect this issue as to not mislead anyone else?

Portable Code: Written purely in JavaScript which means it can be used in Node environment and browser environment (via bundlers like browserify/JSPM/Webpack).

herberthobregon commented 3 years ago

just install npm i stream ✅ https://www.npmjs.com/package/stream

And works.

Update: I move to fast-xml-parser, when bundle with vitejs this lib doesn't work

SignDawn commented 3 years ago

@herberthobregon this package is too old,could error。