3.0.0 • Published 1 year ago
runtime-import v3.0.0
runtime-import
Import remote resource(js or css) asynchronously.
To avoid duplicating runtime-import package, loading a umd bundle file in html is recommended.
The newest umd bundle file is:
https://unpkg.com/runtime-import@3.0.0/dist/runtime-import.umd.js
Install
npm i runtime-import --saveUsage
importScript
Import a javascript file, if the file is in UMD format, return it's export object.
import { importScript } from 'runtime-import'
try {
const $ = await importScript('//foobar.com/jquery.js')
} catch (err) {
console.error(err)
}importStyle
Import a css file.
import { importStyle } from 'runtime-import'
try {
await importStyle('//foobar.com/bootstrap.css')
} catch (err) {
console.error(err)
}importComponent
Import a component. In umd mode, if the entry javascript file is UMD, return it's export object.
Options:
interface ImportComponentOptions {
// JavaScript options.
scripts: {
// Dependent file URLs.
dependencies?: string[]
// UMD entry file URL.
entry: string
// Is the entry file a UMD file? The default value is `true`.
umd?: boolean
// Value of the `crossOrigin` attribute of the <script> element, the default value is "anonymous".
crossOrigin?: string
}
// Stylesheet options.
styles?: {
// CSS URL list.
urls: string[]
}
}Note:
- The default value of the
crossOriginfield inimportComponent's options istrue. This sets thecrossoriginattribute of the<script>elements created byimportComponentto"anonymous". If you do not want thecrossoriginattribute to be set, ensure that thecrossOriginfield inimportComponent's options is set to"".
Example:
import { importComponent } from 'runtime-import'
try {
const bootstrap = await importComponent({
scripts: {
dependencies: []
entry: '//foobar.com/bootstrap.js',
},
styles{
urls: ['//foobar.com/bootstrap.css'],
}
})
} catch (err) {
console.error(err)
}3.0.0
1 year ago
3.0.0-beta.0
1 year ago
2.1.0-beta1
4 years ago
2.1.0-beta3
4 years ago
2.2.1
4 years ago
2.2.0
4 years ago
2.1.0
4 years ago
2.0.3
4 years ago
2.0.2
4 years ago
2.0.1
5 years ago
2.0.0
5 years ago
1.0.12
6 years ago
1.0.11
7 years ago
1.0.10
7 years ago
1.0.9
7 years ago
1.0.8
7 years ago
1.0.7
7 years ago
1.0.6
7 years ago
1.0.5
7 years ago
1.0.4
7 years ago
1.0.3
7 years ago
1.0.2
7 years ago
1.0.1
7 years ago
1.0.0
7 years ago