Code Monkey home page Code Monkey logo

import.js's Introduction

import.js

donate

A dynamic import() polyfill.

Don't miss the related blog post.

Features

  • compatible with native ES2015 modules
  • compatible with native import ... from ...
  • compatible with common native export ... expressions
  • compatible with Babel transpiled ES2015 modules
  • compatible with relative paths
  • compatible with absolute paths

Usage

<!doctype html>
<!-- literally anything you need before -->
<script
    async
    src="import.js"
    data-main="js/main.js"
></script>
  • the src should point to import.js or its min.js version
  • the data-main should point to your module entry point
  • feel free to use or not deferred or async to delay execution
  • all modules will be loaded through XHR to avoid the need of a fetch polyfill
  • however, you can add any polyfill you need upfront

Use https://unpkg.com/import.js@latest as source if you'd like to use a CDN service.

Live test based on this folder.

You can test native ES2015 module export too. It requires a compatible browser (today any modern WebKit would do).

import.js's People

Contributors

webreflection avatar

Stargazers

伊撒尔 avatar Marcos Vinicius  avatar Harsh Wadhwa avatar Dawid Górny avatar Dmitry Iv. avatar Imre Barczi avatar M Peters avatar  avatar Roman Vasilev avatar Arthur A. Bergamaschi avatar Cat  avatar  avatar Alan Greene avatar LGD.HuaFEEng avatar Levi Roberts avatar freemember007 avatar  avatar Wesley Luyten avatar Lucas Costa avatar Denis Denisov avatar Rob Garrison avatar Valmor avatar Christian Vadalà avatar Paweł Lesiecki avatar Hoan Tran avatar Giampaolo Bellavite avatar Tom Bonnike avatar Tomasz Jakut avatar Pato avatar Michele Pangrazzi avatar luigi avatar Andy Woods avatar Tobi Schäfer avatar Andreas Windt avatar Ken Okabe avatar Jas avatar Siva avatar Roberto Soares avatar Alexander Pope avatar Craig Cartmell avatar José Augusto Guimarães avatar Roberto Entringer avatar Dee Cheung avatar himadri.dev avatar Jeff Hykin avatar Petri Kola avatar Yuan Yuan avatar Jonas Kello avatar tanangular avatar Marcus R. Brown avatar Horacio Gonzalez avatar PastLeo avatar Nathan Nelson avatar Madi avatar Caitlin Munley avatar Davo Galavotti avatar Brett Camper avatar David Stone avatar Adnan Chowdhury avatar Rudy Luthi avatar Aleksei Tcelishchev avatar Josh Gillies avatar Stephen Smyth avatar Franz Heinzmann avatar 尹挚 avatar Antoine Pous avatar TheCreation avatar Emerson Thompson avatar Umar Hansa avatar Sylvain Pollet-Villard avatar  avatar Gyujin Cho avatar  avatar codie avatar Bojan Zivkovic avatar Jon Rojí avatar Alberto avatar Vlad Trukhin avatar Stéphane Derosiaux avatar Tom Byrer avatar David Merrique avatar Dong Nguyen avatar Josh Duff avatar  avatar Ray Yee avatar tcme avatar Ivan Čurić avatar Lauren Ancona avatar Pankaj Patel avatar Ben Southgate avatar Shawn Allen avatar  avatar

Watchers

 avatar James Cloos avatar Aleksei Tcelishchev avatar  avatar

import.js's Issues

Feature request: Ponyfill

I would like to have a ponyfill version of this so I can do:

import { import } from "import-ponyfill";

import("./foo/bar").then((m) => m.foo());

If import() has native support like in Chrome 63 then this ponyfill does nothing but proxy to that function. Otherwise it uses the code in this repo.

I think this would be similar to how the fetch-ponyfill works but for modules.

Would it be possible to do something like this?

Babel doesnt work

Babel wont let me transpile the code..

repl: 'import' and 'export' may only appear at the top level (4:4)

  2 | 
  3 | export default function () {
> 4 |     import('../test.js').then(function () {
    |     ^

Use from within web workers

Web workers don't have XHR or DOM

  1. Would it be possible to replace XHR with fetch instead?
  2. Could you change createElement('script') with either eval or constructing a new Function?

My end goal would be to have it in service worker and use async import
doe it's somewhat restricted and i guess it wasn't meant to support async import at first, I mean importScript stops working after it have been installed.
it's only possible to use it durning the installation face, so i would have to use either eval or a Function constructor if i want to add dynamic code.

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.