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

esm-shim-webpack-plugin

v3.0.1

Published

Webpack plugin which emits ${entryName}.mjs for all entries.

Downloads

21

Readme

esm-shim-webpack-plugin

Webpack plugin which emits ${entryName}.mjs for all entries.

Which allows to import amd/umd bundles in esm environment.

It's done by writing .mjs shim file, which imports original umd bundle.

Ofcourse it's hacky, but it allows to have both umd and "esm" bundle, without increasing build time x2.

Have caveats:

  1. entry module should be esm

  2. designed to run in browser, esm shim to umd bundle in nodejs won't work (because of typeof module precendence)

  3. have two network hops, which increases latency.

  4. could have problems with externals module interop:

    If original external was cjs and you built it to be esm bundle (e.g. lodash), it will be {default: mod} module. Which breaks it's usages.

    I don't see a way to distinguish this broken esm and valid esm modules with only default export.

    Which introduces a requirement: externals should be valid esm. Interop won't work here.

Usage:

npm i -D esm-shim-webpack-plugin

const EsmShimPlugin = require('esm-shim-webpack-plugin').default
const conf = {
    ...
    plugins: [new EsmShimPlugin()]
}

Example of generated file:

import * as _imp0 from "mod/external.esm.min.mjs";const __esmWebpackPluginImports = {"mod/external.esm.min.mjs":_imp0};let __esmWebpackPluginMod;const define=(e,n,r)=>{var i,o,t="string"==typeof e,c=t?n:e,l=t?r:n;if(Array.isArray(c))i=c,o=l;else if("object"==typeof c)i=[],o=function(){return c};else{if("function"!=typeof c)throw Error("Invalid call to AMD define()");i=[],o=c}if(__esmWebpackPluginMod)throw new Error("define is called twice, prevExec:\\n"+mod.exec+"\\nnewExec:\\n"+o);let p;const s=i.map((e=>{if("exports"===e)return p={},p;if(!(e in __esmWebpackPluginImports))throw new Error("Can't resolve dependency "+e);return __esmWebpackPluginImports[e]}));let a=o.apply(void 0,s);p&&(a=p),__esmWebpackPluginMod=a};define.amd=!0;(function webpackUniversalModuleDefinition(root, factory) {
	if(typeof exports === 'object' && typeof module === 'object')
		module.exports = factory(require("mod/external.esm.min.mjs"));
	else if(typeof define === 'function' && define.amd)
		define(["mod/external.esm.min.mjs"], factory);
	else {
		var a = typeof exports === 'object' ? factory(require("mod/external.esm.min.mjs")) : factory(root["mod/external.esm.min.mjs"]);
		for(var i in a) (typeof exports === 'object' ? exports : root)[i] = a[i];
	}
})(self, (__WEBPACK_EXTERNAL_MODULE_external__) => {
return /******/ (() => { // webpackBootstrap
//....
});export default __esmWebpackPluginMod.default;export const getDynamic = __esmWebpackPluginMod.getDynamic;export const reexported = __esmWebpackPluginMod.reexported;export const val1 = __esmWebpackPluginMod.val1;

Data url content is file.