Coder Social home page Coder Social logo

webpack-generate-umd-externals's Introduction

webpack-generate-umd-externals

The function is created for very rare use case. Basically it's created for Matreshka.js needs. This doesn't mean you cannot use it in your project, this means I just doubt it :). Anyway the project will become a dependency for things made by me, that's why I publish it.


Matreshka.js framework makes possible to use a global variable Matreshka, require itself via AMD and require itself via CJS. Using CJS I can import specific functions or classes to make application bundle smaller. For example when I want to import bindNode I don't want to load all the framework.

const bindNode = require('matreshka/bindnode');

Matreshka.js is extensible so we can make plugins for it. Plugins should make possible to use global variable, import itself as AMD module and import itself as CJS module as the framework does. But how can we import only needed functions when CJS is used? We need to import all the framework to support all these ways!

This function makes possible to get an access to only needed parts of the framework when you develop a plugin. It gets an object with keys as paths to modules and values as global vars which represent these modules and returns webpack externals and a plugin which concatenates a bundle with named AMD definitions.

const generateExternals = require('webpack-generate-umd-externals');

const { externals, NamedAMDModulesPlugin } = generateExternals({
    'matreshka/bindnode': 'Matreshka.bindNode',
    'matreshka/binders/prop': 'Matreshka.binders.prop'
});

module.exports = {
    entry: '...',
    output: { /* */ },
    externals,
    plugins: [
        new NamedAMDModulesPlugin()
    ]
};

Now you can import listed modules as you usually do in applications.

import bindNode from 'matreshka/bindnode';
// ...

webpack-generate-umd-externals's People

Contributors

finom avatar

Watchers

James Cloos avatar  avatar  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.