lasso-js / lasso

Advanced JavaScript module bundler, asset pipeline and optimizer
581 stars 75 forks source link

Use CDN version of dependency without changing the original source code #195

Closed wangwb closed 7 years ago

wangwb commented 7 years ago
// component.js
const $ = require('jquery')

// browser.json
{
  "dependencies": [
    "require: jquery"
  ]
}

Is it possible to use the CDN version of jquery without changing component.js?

patrick-steele-idem commented 7 years ago

If you want to use the CDN version of jQuery then you should remove const $ = require('jquery') since that will cause it to be bundled and you will have to use the browser.json to include jQuery. Something like the following:

{
  "dependencies": [
    { "type": "js", "url": "https://code.jquery.com/jquery-3.2.0.slim.min.js" }
  ]
}

And just to be clear if you use require('jquery') then you don't need a browser.json. The browser.json is only for including vanilla JS libraries (i.e., not CommonJS modules).

wangwb commented 7 years ago

I don't want to use any global dependencies, that's not the way node module should work. And I also want to replace the disk dependency with a CDN version. That's what I'm looking for. I can see in webpack, there is a way to mark a dependency as an external dependency and then the bundler won't bundle that for you. Is there a similar way in lasso too? Thanks a lot!

wangwb commented 7 years ago

Any thoughts?