3.2.3 • Published 7 years ago

modules-cdn-webpack-plugin v3.2.3

Weekly downloads
9
License
MIT
Repository
github
Last release
7 years ago

modules-cdn-webpack-plugin Build Status codecov

Dynamically get your dependencies from a cdn rather than bundling them in your app

Install

$ npm install --save modules-cdn-webpack-plugin module-to-cdn

Usage with HtmlWebpackPlugin

webpack.config.js

const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const ModulesCdnWebpackPlugin = require('modules-cdn-webpack-plugin');

module.exports = {
    entry: {
        'app.js': './src/app.js'
    },

    output: {
        path.resolve(__dirname, './build'),
    },

    plugins: [
        new HtmlWebpackPlugin(),
        new ModulesCdnWebpackPlugin()
    ]
}

app.js

import React from 'react';
import { BrowserRouter } from 'react-router-dom';

// ... do react stuff

NODE_ENV=production webpack will generate:

/* simplified webpack build */
[function(module, __webpack_exports__, __webpack_require__) {
    module.exports = React;
}),
(function(module, __webpack_exports__, __webpack_require__) {
    module.exports = ReactRouterDOM;
}),
(function(module, __webpack_exports__, __webpack_require__) {
    var react = __webpack_require__(0);
    var reactRouterDOM = __webpack_require__(1);

    /* ... */
})]
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>
  </head>
  <body>
    <script type="text/javascript" src="https://unpkg.com/react@15.5.3/dist/react.min.js"></script><script type="text/javascript" src="https://unpkg.com/react-router-dom@4.1.1/umd/react-router-dom.min.js"></script><script src="build/app.js"></script></body>
</html>

Usage with ManifestPlugin

webpack.config.js

const path = require('path');

const ManifestPlugin = require('webpack-manifest-plugin');
const ModulesCdnWebpackPlugin = require('modules-cdn-webpack-plugin');

module.exports = {
    entry: {
        'app': './src/app.js'
    },

    output: {
        path.resolve(__dirname, './build'),
    },

    plugins: [
        new ManifestPlugin({
            fileName: 'manifest.json'
        }),
        new ModulesCdnWebpackPlugin()
    ]
}

app.js

import React from 'react';
import { BrowserRouter } from 'react-router-dom';

// ... do react stuff

NODE_ENV=production webpack will generate:

/* simplified webpack build */
[function(module, __webpack_exports__, __webpack_require__) {
    module.exports = React;
}),
(function(module, __webpack_exports__, __webpack_require__) {
    module.exports = ReactRouterDOM;
}),
(function(module, __webpack_exports__, __webpack_require__) {
    var react = __webpack_require__(0);
    var reactRouterDOM = __webpack_require__(1);

    /* ... */
})]
{
    "app.js": "app.js",
    "react.js": "https://unpkg.com/react@15.5.3/dist/react.min.js",
    "react-router-dom.js": "https://unpkg.com/react-router-dom@4.1.1/umd/react-router-dom.min.js"
}

API

ModulesCdnWebpackPlugin(options)

options.disable

Type: boolean Default: false

Usefull when working offline, will fallbacl to webpack normal behaviour

options.env

Type: string Default: process.env.NODE_ENV || 'development' Values: development, production

Determine if it should load the development or the production version of modules

options.only

Type: Array<string> Default: null

List the only modules that should be served by the cdn

options.exclude

Type: Array<string> Default: []

List the modules that will always be bundled (not be served by the cdn)

options.verbose

Type: boolean Default: false

Log whether the library is being served by the cdn or is bundled

Related

Contributors

Thanks goes to these wonderful people (emoji key):

Thomas Sileghem💻 📖 ⚠️MICHAEL JACKSON💡

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Thomas Sileghem

3.2.3

7 years ago

3.2.2

7 years ago

3.2.1

7 years ago

3.2.0

7 years ago

3.1.1

7 years ago

3.1.0

7 years ago

3.0.4

7 years ago

3.0.3

7 years ago

3.0.2

7 years ago

3.0.1

7 years ago

3.0.0

7 years ago

2.1.3

7 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

1.0.2

7 years ago

2.0.0

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago