CDN with fallback extension for the HTML Webpack Plugin
Enhances html-webpack-plugin
functionality by loading all script
body tags with fallbackjs.
This is an extension plugin for the webpack plugin html-webpack-plugin (version 4 or higher). It allows you to load javascript files from a cdn and fallback to self hosting if the cdn can't be reached.
This extension is based on the source code of html-webpack-inline-source-plugin.
Installation
You must be running webpack on node 6 or higher.
Install the plugin with npm:
$ npm install --save-dev html-webpack-cdn-fallback-plugin
Basic Usage
Require the plugin in your webpack config:
var HtmlWebpackCdnFallbackPlugin = ;
Add the plugin to your webpack config as follows:
plugins: HtmlWebpackPlugincdnUrl: 'https://your-cdn.com/basepath/:version/'
This will replace all script
tags from the body that have a src
attribute with one script tag containing calls to fallbackjs.
without plugin:
with plugin:
Options
cdnUrl
Can be either a string or a function returning a string. :version
will be replaced with the veriosn of your package.json. :commit
will be replaced with the commit sha of your repository.
Usage with react-app-rewired
config-override.js
const HtmlWebPackCdnFallbackPlugin = ;moduleexports = ;