GithubHelp home page GithubHelp logo

hhy5277 / import-http Goto Github PK

View Code? Open in Web Editor NEW

This project forked from egoist/import-http

0.0 1.0 0.0 2.39 MB

Import modules from URL instead of local node_modules

License: MIT License

JavaScript 100.00%

import-http's Introduction

logo


NPM version NPM downloads CircleCI donate chat

Please consider donating to this project's author, EGOIST, to show your ❤️ and support.

Introduction

  • Imports source code URLs! Like <script type="module"> and Deno but implemented as a webpack/Rollup plugin. Embracing the future :)

    import template from 'https://unpkg.com/lodash-es/template'
    
    console.log(template(`Hello <%= name %>`)({ name: 'EGOIST' }))

    Remote code is fetched and cached on first build, and never updated until you use the reload option. See more about Caching.

  • No more node_modules bloat, no dependency to install.

image

Install

yarn add import-http --dev

Usage

Webpack

In your webpack.config.js:

const ImportHttpWebpackPlugin = require('import-http/webpack')

module.exports = {
  plugins: [new ImportHttpWebpackPlugin()]
}

That's it, try following code:

import React from 'https://unpkg.com/react'
import Vue from 'https://unpkg.com/vue'

console.log(React, Vue)

Run webpack and it just works.

Rollup

In your rollup.config.js:

export default {
  plugins: [require('import-http/rollup')()]
}

Caching

Resources will be fetched at the very first build, then the response will be cached in ~/.cache/import-http dir. You can use the reload option to invalidate cache:

const ImportHttpWebpackPlugin = require('import-http/webpack')

module.exports = {
  plugins: [
    new ImportHttpWebpackPlugin({
      reload: process.env.RELOAD
    })
  ]
}

Then run RELOAD=true webpack to update cache.

Contributing

  1. Fork it!
  2. Create your feature branch: git checkout -b my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin my-new-feature
  5. Submit a pull request :D

Author

import-http © EGOIST, Released under the MIT License.
Authored and maintained by EGOIST with help from contributors (list).

Website · GitHub @EGOIST · Twitter @_egoistlily

import-http's People

Contributors

c4software avatar egoist avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.