https://github.com/maple3142/require-unpkg
require from unpkg.com in browser
https://github.com/maple3142/require-unpkg
browser javascript module require unpkg
Last synced: 10 months ago
JSON representation
require from unpkg.com in browser
- Host: GitHub
- URL: https://github.com/maple3142/require-unpkg
- Owner: maple3142
- License: mit
- Created: 2017-09-09T03:41:39.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-02T06:55:12.000Z (almost 6 years ago)
- Last Synced: 2025-06-06T23:08:18.090Z (11 months ago)
- Topics: browser, javascript, module, require, unpkg
- Language: JavaScript
- Homepage:
- Size: 1.18 MB
- Stars: 4
- Watchers: 2
- Forks: 1
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# require-unpkg
[](https://greenkeeper.io/)
[](https://travis-ci.org/maple3142/require-unpkg)
## require from [unpkg.com](https://unpkg.com/) in browser
### [Example](https://rawgit.com/maple3142/require-unpkg/master/test.html)
### [Example(codepen)](https://codepen.io/maple3142/pen/qXebVQ)
```html
Example
require.cache.expire = 100000; //set cache time (DONT SET TO 0), default: 24 hours
//with es7 async/await:
(async function () {
let $ = await require('jquery')
$('#jquery').text('jquery hello world')
})()
//with Promise+Array Destructuring:
require(['vue','vuejs-storage']).then(([Vue,vuejsStorage]) => {
Vue.use(vuejsStorage)
new Vue({
el: '#vue',
storage: {
data: {
input: ''
},
namespace: 'test'
}
})
})
```
## Extra
### \_require
`require._require` only require single module only ex: `require._require('jquery')`
### \_get
`require._get` provide simple xhr `GET` function ex:`require._get(url)`
### node.js
To use in node.js environment, you must set
```javascript
const urequire = require('unpkg-require')
urequire.XMLHttpRequest = XHR_POLYFILL //like xhr2...
urequire('lodash').then(_ => {})
```
~~But I don't know why to require unpkg instead of `node_modules`~~