dynamic-cdn-webpack-plugin
Dynamically get your dependencies from a cdn rather than bundling them in your app
Install
$ npm install --save-dev dynamic-cdn-webpack-plugin 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 = ; const HtmlWebpackPlugin = ;const DynamicCdnWebpackPlugin = ; moduleexports = entry: 'app.js': './src/app.js' output: path plugins:
app.js
;; // ... do react stuff
webpack --mode=production
will generate:
/* simplified webpack build */ { moduleexports = React;}) { moduleexports = ReactRouterDOM;} { var react = ; var reactRouterDOM = ; /* ... */}
Webpack App
Usage with ManifestPlugin
webpack.config.js
const path = ; const ManifestPlugin = ;const DynamicCdnWebpackPlugin = ; moduleexports = entry: 'app': './src/app.js' output: path plugins: fileName: 'manifest.json'
app.js
;; // ... do react stuff
webpack --mode=production
will generate:
/* simplified webpack build */ { moduleexports = React;}) { moduleexports = ReactRouterDOM;} { var react = ; var reactRouterDOM = ; /* ... */}
API
DynamicCdnWebpackPlugin(options)
webpack.config.js
const DynamicCdnWebpackPlugin = ; moduleexports = mode: 'production' plugins: 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.verbose
Type: boolean
Default: false
Log whether the library is being served by the cdn or is bundled
options.resolver
Type: string
, function
Default: '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
.
Related
Contributors
Thanks goes to these wonderful people (emoji key):
Thomas Sileghem 💻 📖 ⚠️ |
Faizaan 💬 💻 📖 |
MICHAEL JACKSON 💡 |
fedeoo 💻 |
---|
This project follows the all-contributors specification. Contributions of any kind welcome!
License
MIT © Thomas Sileghem