Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External dependencies are not bundled in the UMD build #179

Open
luisrudge opened this issue Aug 15, 2019 · 10 comments
Open

External dependencies are not bundled in the UMD build #179

luisrudge opened this issue Aug 15, 2019 · 10 comments
Labels
scope: docs Documentation could be improved. Or changes that only affect docs topic: externals Related to configuring externals for Rollup

Comments

@luisrudge
Copy link

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
@azizhk
Copy link

azizhk commented Aug 26, 2019

We are facing similar issue:
Can tsdx allow us a way to change the externals functions.
https://github.com/palmerhq/tsdx/blob/73b152eca021ab4897efa92d8ec3abb893fc8b96/src/utils.ts#L21-L22

@azizhk
Copy link

azizhk commented Aug 27, 2019

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;
  }
}

@luisrudge
Copy link
Author

I'll test when 0.9.0 is released

@sadsa
Copy link
Contributor

sadsa commented Sep 4, 2019

Hi there, what was the status on this after this release to 0.9.0?

@tabuckner
Copy link

@luisrudge did you get a chance to test anything out yet, this backs into one of my questions as well.

@luisrudge
Copy link
Author

@tabuckner sorry, I didn't. I changed my focus and had to let it go. sorry!

@jimmyn
Copy link

jimmyn commented Mar 28, 2020

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?

@agilgur5
Copy link
Collaborator

agilgur5 commented Mar 28, 2020

@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. 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. removing external is fairly easy to configure right now.

@jimmyn
Copy link

jimmyn commented Mar 29, 2020

@agilgur5 your solution works fine for me, thanks. Maybe it is worth mentioning in the documentation somewhere.

@YukiYuko
Copy link

@agilgur5

@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. 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. removing external 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"
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: docs Documentation could be improved. Or changes that only affect docs topic: externals Related to configuring externals for Rollup
Projects
None yet
Development

No branches or pull requests

7 participants