Created
April 5, 2019 02:14
-
-
Save aulisius/e60ed5290be3a784162f7133c5c343d7 to your computer and use it in GitHub Desktop.
DynamicCDNWebpackPlugin with custom resolver for React (CDN as jsDelivr)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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