xml.js icon indicating copy to clipboard operation
xml.js copied to clipboard

Difficult to use from Webpack

Open lapo-luchini opened this issue 6 years ago • 6 comments

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 [email protected] 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'
            ]
        }],
    },
};
```

lapo-luchini avatar Mar 21 '19 13:03 lapo-luchini

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

Tasemu avatar Sep 09 '19 15:09 Tasemu

+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.

s4m0r4m4 avatar Apr 09 '20 17:04 s4m0r4m4

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.

kripken avatar Apr 09 '20 18:04 kripken

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

philipsens avatar Nov 20 '20 16:11 philipsens

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

s4m0r4m4 avatar Nov 20 '20 18:11 s4m0r4m4

@philipsens, were you able to find any workaround?

NullPointer26 avatar Nov 22 '22 06:11 NullPointer26