Code Monkey home page Code Monkey logo

Comments (3)

jacksteamdev avatar jacksteamdev commented on August 15, 2024

Hi @micah-yeager, thanks for the heads up on the broken link! 👍

I just updated the link and added more information on the dynamic import wrapper.

Let me know what your think!


⭐️ Use ES2015 Modules In Your Scripts

Chrome extensions don't support modules in background and content scripts. We've developed a module loader specifically for Chrome extension scripts, so you can take advantage of Rollup's great code splitting features.

⭐️ How does the dynamic import wrapper work?

TLDR; RPCE parses the manifest and replaces any script path with an IIFE wrapper that loads the script using a dynamic import statement.

See Why do we need to use dynamic import in scripts? for the reasons we need dynamic imports.

Content scripts are pretty straight forward, and the wrapper they use is just an IIFE that loads the script and logs any import errors.

Background pages need a special wrapper because wake events (onInstalled, onMessage, etc...) fire before the import completes. We make sure we don’t miss any events by capturing all events that occur before the import promise resolves and then re-dispatch them after the import completes.

from chrome-extension-tools.

micah-yeager avatar micah-yeager commented on August 15, 2024

That makes a lot more sense. So am I correct in thinking that it doesn't need anything special to work out of the box, just use normal import statements in the background script?

from chrome-extension-tools.

jacksteamdev avatar jacksteamdev commented on August 15, 2024

@micah-yeager That's right! (sorry for the long delay)

from chrome-extension-tools.

Related Issues (20)

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.