3.0.1 • Published 8 months ago

sharedrequireplugin v3.0.1

Weekly downloads
25
License
MIT
Repository
-
Last release
8 months ago

Shared Require Plugin for Webpack

This Webpack plugin enables you to share the code require()'d in one project with another. With this plugin, you can compile code in one js file and use it in another without having duplicate instances of code.

Install

use "npm install sharedrequireplugin" to download and install

Examples

ProjectA - Contains JQuery -

webpack.config.js

import { SharedRequirePlugin } from "sharedrequireplugin/webpack";

export default {
    entry: "...",
    output: {..},
    resolve: {...},
    module: {...},
    plugins: [
        new SharedRequirePlugin({
            provides: {
                "@polymer/polymer": { eager: true },
                "jquery": { eager: true },

                ...
            }
        }),
    ]
};

ProjectB - Uses JQuery -

webpack.config.js

import { SharedRequirePlugin } from "sharedrequireplugin/webpack";

export default {
    entry: "...",
    output: {..},
    resolve: {...},
    module: {...},
    plugins: [
        new SharedRequirePluginWebpack ({
            externalModules: [
                /\@polymer\/polymer/g,
                "jquery"
            ]
        }),
        ...
    ]
};

externalModules now support regex expressions.

This will reduce the size of ProjectB's JS file.
Ensure ProjectA is loaded before ProjectB attempts to use the jquery library.

If ProjectA has not been loaded then a the require("jquery") call in ProjectB will return null.

This component uses the internal ProvideSharedPlugin to enter shared modules into webpack's shared space, then provides a mechanism for accessing these shared modules globally.

Shared Require Plugin for Rollup

This Webpack plugin enables you to share the code require()'d in one project with another. With this plugin, you can compile code in one js file and use it in another without having duplicate instances of code.

Install

use "npm install sharedrequireplugin" to download and install

Examples

ProjectB - Uses JQuery -

rollup.config.js

import { SharedRequirePlugin} from "sharedrequireplugin/rollup";

export default [
    {
        input: "src/main.ts",

        output: [
            {
                file: "dist/index.esm.js",
                format: "es"
            },
            {
                file: "dist/index.cjs.js",
                format: "cjs",

            }
        ],
        plugins: [
            nodeResolve(),
            SharedRequirePluginRollup({
                external: [
                    "jquery",
                ]
            }),
            ...
        ]
    }
];
3.0.1

8 months ago

2.0.11

12 months ago

2.0.9

1 year ago

2.0.10

12 months ago

2.0.7

1 year ago

2.0.6

1 year ago

2.0.8

1 year ago

2.0.2

2 years ago

2.0.5

2 years ago

2.0.4

2 years ago

2.0.1

2 years ago

2.0.0

2 years ago

1.1.15

4 years ago

1.1.14

4 years ago

1.1.13

4 years ago

1.1.12

4 years ago

1.1.11

4 years ago

1.1.9

4 years ago

1.1.10

4 years ago

1.1.8

4 years ago

1.1.7

4 years ago

1.1.6

4 years ago

1.1.5

4 years ago

1.1.4

4 years ago

1.1.3

4 years ago

1.1.2

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

0.1.5

8 years ago

0.1.4

9 years ago

0.1.3

9 years ago

0.1.2

9 years ago

0.1.1

9 years ago

0.1.0

9 years ago

0.0.1

9 years ago