Indirectly reference remote Javascript URL
We want to use Rollup with Angular 4/Typescript and NPM We have the following requirement within our company:
What is the best way to achieve this using Typescript/Javascript/NPM/Rollup? We would use ES2015 syntax transpiled to commonJS syntax.
I don't think rollup has something similar to webpack dll plugin , so, my answer may appear unrelated but I think you could assume it as a good starting point and start looking for something similar in rollup.
a library living in a CDN :
DLL
with its corresponding DLL Reference
which exactly describes how to require the exported modules. https://cdn.mydomain.com/<libraryName>/<version>/<libraryName>.{js,json,d.ts}
(the requester should add ?<cacheBustingUID>
to avoid client caching issues). In addition to the normal versioning, I also suggest you to use a keyword latest
for the version
field, this to achieve an always true path
which points to the latest version of the bundle: ( https://cdn.mydomain.com/foo/1.0.0/foo.{js,json,d.ts}
, and https://cdn.mydomain.com/foo/latest/foo.{js,json,d.ts}
). module.exports = env => {
const libs = ((name, version, exts) => (
exts.map(ext => `https://cdn.mydomain.com/${name}/${version}/${name}.${ext}`)
))('foo', 'latest', ['js', 'd.ts', 'json'])
return Promise
.all(libs.map(fetch))
.then([library, definitions, DLLReference] => {
// what to do?
// you can also inject the dynamic paths through `webpackDefinePlugin`
})
}
The solution is too complex. The teams who create those JS libraries should put a bundle behind a URL. Teams should put that URL and eTag caching should be enabled on those bundles so that users always have the latest version. If a new version of the bundle is deployed the http/1 clients automatically have to redownload the bundle.
Users have to put the URL themselves or a mechanism with json files could be set up where the information resides in json files (like a manifest).
The developers of the application could receive a d.ts file through npm containing all typings of the frameworking library. You won't need to import modules because it's a remote URL. So you don't need to import anything because it's guaranteed that the library is referenced because of a script tag.
链接地址: http://www.djcxy.com/p/39598.html上一篇: React路由器v4角色基础授权
下一篇: 间接引用远程JavaScript URL