14.0.0 • Published 4 months ago

@talend/dynamic-cdn-webpack-plugin v14.0.0

Weekly downloads
1,085
License
MIT
Repository
github
Last release
4 months ago

dynamic-cdn-webpack-plugin

NPM

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

Warning: This module is a fork from https://github.com/mastilver/dynamic-cdn-webpack-plugin. We start to fork after month without update and because we need to ship our libs and project over CDN leverage UMD builds.

The underlying module-to-cdn for the same reason has also been forked https://npmjs.org/package/@talend/module-to-cdn.

Install

$ npm install --save-dev @talend/dynamic-cdn-webpack-plugin @talend/module-to-cdn

Compatibility with webpack

If you are using webpack --version <= 3 then you should be installing with the following command.

$ npm install --save-dev dynamic-cdn-webpack-plugin@3.4.1 module-to-cdn

Usage with HtmlWebpackPlugin

webpack.config.js

const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const DynamicCdnWebpackPlugin = require('@talend/dynamic-cdn-webpack-plugin');

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

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

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

app.js

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

// ... do react stuff

webpack --mode=production 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 { WebpackManifestPlugin } = require('webpack-manifest-plugin');
const DynamicCdnWebpackPlugin = require('@talend/dynamic-cdn-webpack-plugin');

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

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

    plugins: [
        new WebpackManifestPlugin({
            fileName: 'manifest.json'
        }),
        new DynamicCdnWebpackPlugin()
    ]
}

app.js

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

// ... do react stuff

webpack --mode=production 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

DynamicCdnWebpackPlugin(options)

webpack.config.js

const DynamicCdnWebpackPlugin = require('@talend/dynamic-cdn-webpack-plugin');

module.exports = {
	mode: 'production',
	plugins: [new DynamicCdnWebpackPlugin(options)],
};

options.disable

Type: boolean Default: false

Useful when working offline, will fallback to webpack normal behaviour

options.env

Type: string Default: mode 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.loglevel

Type: string Default: ERROR Options: ERROR, INFO, DEBUG

ERROR:

  • module XX could not be loaded because peerDependency YY is not loaded

INFO:

  • module XX already loaded in another version

DEBUG:

options.resolver

Type: string, function Default: '@talend/module-to-cdn'

Allow you to define a custom module resolver, it can either be a function or an npm module. The resolver should return (or resolve as a Promise) either null or an object with the keys: name, var, url, version.

options.addURL

Type: function

This function should be aligned with the resolver to support dependencies manifest. It take builted info from it and add cdn url to the info structure to have align values.

Related

Contributors

Thanks goes to these wonderful people (emoji key):

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

License

MIT © Thomas Sileghem

14.0.0

4 months ago

13.1.2

7 months ago

13.1.1

7 months ago

13.1.0

11 months ago

13.0.1

1 year ago

12.0.0

2 years ago

13.0.0

2 years ago

11.1.1

2 years ago

11.1.0

2 years ago

11.0.2

2 years ago

11.0.3

2 years ago

11.0.0

2 years ago

11.0.1

2 years ago

9.7.15

3 years ago

9.7.14

3 years ago

9.7.13

3 years ago

9.7.12

3 years ago

9.7.10

3 years ago

9.7.11

3 years ago

9.7.9

3 years ago

9.7.8

3 years ago

9.7.7

3 years ago

9.7.6

3 years ago

9.7.5

3 years ago

9.7.4

3 years ago

9.7.3

3 years ago

9.7.2

4 years ago

9.7.1

4 years ago

9.7.0

4 years ago

9.7.0-jso.1

4 years ago

9.7.0-jso.0

4 years ago

9.6.3

4 years ago

9.7.0-alpha.0

4 years ago

9.7.0-alpha.1

4 years ago

9.6.2

4 years ago

9.6.1

4 years ago

9.6.0

4 years ago

9.5.1

4 years ago

9.5.0

4 years ago

9.4.1

4 years ago

9.4.0

4 years ago

9.3.2

4 years ago

10.1.0

4 years ago

10.0.1

4 years ago

10.0.2

4 years ago

9.3.1

4 years ago

9.3.0

4 years ago

10.0.0

4 years ago

10.0.0-alpha.1

4 years ago

9.2.2

4 years ago

9.2.2-alpha.0

4 years ago

9.2.1

4 years ago

9.2.1-alpha.6

4 years ago

9.2.1-alpha.5

4 years ago

9.2.1-alpha.4

4 years ago

9.2.1-alpha.0

4 years ago

9.2.1-alpha.2

4 years ago

9.2.1-alpha.1

4 years ago

9.2.1-alpha.3

4 years ago

9.2.0

4 years ago

9.2.0-alpha.0

4 years ago

9.2.0-alpha.1

4 years ago

9.1.0

4 years ago

9.0.1

4 years ago

9.1.0-ng.0

4 years ago

7.5.1

4 years ago

9.1.0-alpha.0

4 years ago

9.0.0

4 years ago

8.0.2

4 years ago

9.0.0-jest.0

4 years ago

8.0.1-jest.0

4 years ago

8.0.1

4 years ago

8.0.0

4 years ago

7.5.1-alpha.0

4 years ago

7.5.0

4 years ago

8.0.0-jest.26

4 years ago

7.4.3

4 years ago

7.4.2

4 years ago

7.4.1

4 years ago

7.4.0

4 years ago

7.3.1

4 years ago

8.0.0-alpha.2

4 years ago

8.0.0-alpha.1

4 years ago

7.3.0

4 years ago

7.2.1

4 years ago

7.1.3

4 years ago

7.2.0

4 years ago

7.1.2

4 years ago

7.1.1

4 years ago

7.1.0

4 years ago

6.10.1

4 years ago

7.0.5

4 years ago

7.0.4

4 years ago

7.0.2-alpha.0

4 years ago

7.0.2-alpha.1

4 years ago

7.0.3

4 years ago

7.0.2

4 years ago

7.0.1

4 years ago

7.0.1-alpha.0

4 years ago

7.0.1-alpha.1

4 years ago

6.10.0

4 years ago

7.0.0

4 years ago

5.5.2

4 years ago

5.5.1

4 years ago

5.5.0

4 years ago

5.4.0

4 years ago

5.2.2

4 years ago

5.3.0

4 years ago

5.2.1

4 years ago

5.2.0

4 years ago

5.1.2

4 years ago

5.1.1

4 years ago

5.1.0

4 years ago

5.0.0

4 years ago