Skip to content

Instantly share code, notes, and snippets.

@aulisius
Created April 5, 2019 02:14
Show Gist options
  • Save aulisius/e60ed5290be3a784162f7133c5c343d7 to your computer and use it in GitHub Desktop.
Save aulisius/e60ed5290be3a784162f7133c5c343d7 to your computer and use it in GitHub Desktop.
DynamicCDNWebpackPlugin with custom resolver for React (CDN as jsDelivr)
const HtmlWebpackPlugin = require("html-webpack-plugin");
const DynamicCdnWebpackPlugin = require("dynamic-cdn-webpack-plugin");
module.exports = {
mode: "production",
plugins: [
new HtmlWebpackPlugin(),
new DynamicCdnWebpackPlugin({
resolver: (packageName, packageVersion, options) => {
let env = options.env || "development";
if (packageName === "react") {
return {
name: packageName,
var: "React",
version: packageVersion,
url: `https://cdn.jsdelivr.net/npm/${packageName}@${packageVersion}/umd/react.${env}.min.js`
};
} else {
return null;
}
}
})
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment