Skip to content

无需配置 webpack externals 自动向 html-webpack-plugin 模板注入 unpkg cdn

License

Notifications You must be signed in to change notification settings

zzlw/html-webpack-cdn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

npm node GitHub issues GitHub forks GitHub stars GitHub license

html-webpack-cdn

无需配置 webpack externals 自动向 html-webpack-plugins 模板注入 unpkg cdn

Install

Webpack 5

  npm i --save-dev html-webpack-cdn
  yarn add --dev html-webpack-cdn
// 无需配置 webpack externals
// modules 为空则不会生效
const WebpackHtmlCdnPlugin = require("html-webpack-cdn");

const cdnEnv = process.env.NODE_ENV === 'development' ? 'development' : 'production.min';

new HtmlWebpackCdnPlugin({
  modules: [
    { name: 'react', _var: 'React', path: `umd/react.${cdnEnv}.js` },
    { name: 'react-dom', _var: 'ReactDOM', path: `umd/react-dom.${cdnEnv}.js` },
  ],
})
<!-- html 中效果 -->
<script src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script>

About

无需配置 webpack externals 自动向 html-webpack-plugin 模板注入 unpkg cdn

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published