tsdx
tsdx copied to clipboard
External dependencies are not bundled in the UMD build
Current Behavior
My project has a few dependencies (qs
, fast-text-encoding
and es-cookie
). When I build the UMD bundle, the dependencies are not bundled together with my code.
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('fast-text-encoding'), require('qs'), require('es-cookie')) :
typeof define === 'function' && define.amd ? define(['exports', 'fast-text-encoding', 'qs', 'es-cookie'], factory) :
(global = global || self, factory(global.createAuth0Client = {}, null, global.qs, global.Cookies));
}(this, function (exports, fastTextEncoding, qs, Cookies) { 'use strict';
// ... some code
}));
Expected behavior
I expect all my dependencies to be bundled together with my code
Suggested solution(s)
Maybe it's a rollup config? I have no idea :(
Your environment
Software | Version(s) |
---|---|
TSDX | 0.8.0 |
TypeScript | 3.5.3 |
Browser | n/a |
npm/Yarn | npm 6.9.0 |
Operating System | windows 10 |
We are facing similar issue:
Can tsdx allow us a way to change the external
s functions.
https://github.com/palmerhq/tsdx/blob/73b152eca021ab4897efa92d8ec3abb893fc8b96/src/utils.ts#L21-L22
I think this should get fixed by #183 by creating a tsdx.config.js
// tsdx.config.js
module.exports = {
rollup(config, options) {
config.external = (id) => false;
return config;
}
}
I'll test when 0.9.0 is released
Hi there, what was the status on this after this release to 0.9.0?
@luisrudge did you get a chance to test anything out yet, this backs into one of my questions as well.
@tabuckner sorry, I didn't. I changed my focus and had to let it go. sorry!
Any solution to this? I'm also struggling with this issue. When I bundle UMD build my dependencies are not included. @azizhk solution is not working for me because it raises another error. I wonder why this is not a default behavior. If you create a lib to drop into a script tag you expect all the dependencies get included in a single file. Am I missing something?
@jimmyn config.external = (id) => false;
should work. as should delete config.external
. In full form:
tsdx.config.js
:
module.exports = {
rollup(config) {
if (config.output.format === 'umd') {
delete config.external;
}
return config;
}
}
What other error did you get? If this were supported internally it would basically look the same.
I'm not totally sure why it's not the default behavior -- I think that's just historically adopted from microbundle
's behavior (c.f. https://github.com/developit/microbundle/issues/95)
I do think it could make sense to change the default as some other tools do bundle UMD by default. However, there are ways to "import" other libraries into UMD, pending your environment (UMD can be used in Node too). In the browser, you could get your dependencies from CDN to prevent duplication.
If we made this the default for UMD, it would make it more difficult to get back the current behavior for external
, vs. removing external
is fairly easy to configure right now.
@agilgur5 your solution works fine for me, thanks. Maybe it is worth mentioning in the documentation somewhere.
@agilgur5
@jimmyn
config.external = (id) => false;
should work. as shoulddelete config.external
. In full form:
tsdx.config.js
:module.exports = { rollup(config) { if (config.output.format === 'umd') { delete config.external; } return config; } }
What other error did you get? If this were supported internally it would basically look the same.
I'm not totally sure why it's not the default behavior -- I think that's just historically adopted from
microbundle
's behavior (c.f. developit/microbundle#95)I do think it could make sense to change the default as some other tools do bundle UMD by default. However, there are ways to "import" other libraries into UMD, pending your environment (UMD can be used in Node too). In the browser, you could get your dependencies from CDN to prevent duplication. If we made this the default for UMD, it would make it more difficult to get back the current behavior for
external
, vs. removingexternal
is fairly easy to configure right now.
When I use this method the console gets another prompt, 'parseRtpParameters' is not exported by 'node_modules\sdp\ SDp.js' But it was successfully packaged and I don't know if it had any effect on the packaged code.
this is my "devDependencies": { "@size-limit/preset-small-lib": "^11.1.2", "@types/lodash": "^4.17.0", "husky": "^9.0.11", "size-limit": "^11.1.2", "tsdx": "^0.14.1", "tslib": "^2.6.2", "typescript": "5.1.6" },