kripken / xml.js

Port of libxml to JavaScript using Emscripten
Other
174 stars 67 forks source link

Difficult to use from Webpack #27

Open lapo-luchini opened 5 years ago

lapo-luchini commented 5 years ago

Due to the way that environments are detected it is difficult to use from Webpack, as both Node is detected (thus requiring fs and ws) and window is detected (thus not exporting to module.exports). Those issues can be worked around using imports-loader and exports-loader, but it would probably be nice to have a way to detect Webpack and "just work" OOTB.

I was capable of using xmllint@0.1.1 using the following configuration:

module.exports = {
    mode: 'production',
    …
    node: {
        // required by xmllint (but not really used in the browser)
        fs: 'empty',
    },
    externals: {
        // required by xmllint (but not really used in the browser)
        ws: '{}',
    },
    module: {
        rules: [{
            test: path.resolve(__dirname, 'node_modules/xmllint/xmllint.js'),
            use: [
                'imports-loader?require=>null',
                'exports-loader?xmllint'
            ]
        }],
    },
};
Tasemu commented 4 years ago

+1 this caused us a lot of grief before i found this issue

s4m0r4m4 commented 4 years ago

+1 from me too. Trying to use this in a typescript/angular project and importing and/or requiring it is not working. I can't claim to know that much about designing javascript libraries, but it would be great if we could import this using the new ESM approach:

import {xmllint} from 'xmllint';

https://github.com/kripken/xml.js/issues/24 seems related. @kripken is this library still supported? If so, I may be willing to look into this kind of support.

kripken commented 4 years ago

I don't have time to support it myself, sorry @s4m0r4m4 :cry:

Would be great if you have time for that! I can help with emscripten questions if there are any.

philipsens commented 3 years ago

Is there any progress regarding an import statement for ESM or TS? @s4m0r4m4

s4m0r4m4 commented 3 years ago

Sorry no, I ended up going a different direction with my project and not using this library.

NullPointer26 commented 1 year ago

@philipsens, were you able to find any workaround?