npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rtvision/esbuild-dynamic-import

v2.0.2

Published

Plugin for transform dynamic imports in esbuild

Downloads

3,919

Readme

Esbuild Dynamic Import

Version Downloads/week License

Features

-Transforms dynamic imports that contain a template string variable into static imports to be processed by esbuild

-Rewrites dynamic imports of js files that contain a template string variable to use absolute path instead

Install

npm i @rtvision/esbuild-dynamic-import

I know this was working using the version 0.13.14 of esbuild. It may work for earlier versions depending on when the plugin system was implemented

Example Usage

import DynamicImport from '@rtvision/esbuild-dynamic-import';
DynamicImport({ transformExtensions: ['.vue'], changeRelativeToAbsolute: true, filter: /src\/.*\.js$/ }),

Parameters

transformExtensions

Transforms all dynamic imports that contain a template varable and the imported file extension is included in transformExtensions. I.E. import(``../../${file}.vue``) All imports found will be turned into static imports of every possible valid import it could be. It then uses the static imports instead of node dynamically importing the file at runtime

My use case for this was I wanted esbuild to process the possible imports that are .vue (SFC vue) files so they can be processed by the EsbuildVue plugin and made into valid javascript that nodejs can run.

changeRelativeToAbsolute

If there exists a dynamic import like import(``../../${file}.js``) then that in theory could be resolved at runtime just fine by nodejs. The main issue is that the relative file path is now different due to the bundled file produced by esbuild being in a likely different file location. changeRelativeToAbsolute will fix this issue by changing all relative dynamic imports that contain a template literal variable to absolute ones.

For my use case dynamic imports while using vite are needed to be relative for production builds especially since Rollup is currently used and Rollup requires all dynamic imports to be relative.

Filter

The Filter parameter is used to reduce the scope of the file search.

I set it to just search our local source directory, but by default it will search through every js file that is not marked as external

Loader

Need to specify if you need one of esbuild's internal loaders to transform the file after the dynamic imports are handled by this plugin. i.e. if your filter is /.jsx$/ then you need to specify jsx as your loader

License

MIT © RtVision