@effortlessmotion/dynamic-cdn-webpack-plugin

中文文档
5.0.1发布于 2021/07/04MITCommonJS近 30 天下载 1.3万

Dynamically get your dependencies from a cdn rather than bundling them in your app

原始使用文档
文档目录9 节
  1. Install
  2. Compatibility with webpack
  3. Usage with HtmlWebpackPlugin
  4. Usage with ManifestPlugin
  5. API
  6. DynamicCdnWebpackPlugin(options)
  7. Related
  8. Contributors
  9. License

dynamic-cdn-webpack-plugin

npm Build Status codecov David XO code style

Dynamically get your dependencies from a cdn rather than bundling them in your app

Warning: This module is a fork from https://github.com/mastilver/dynamic-cdn-webpack-plugin to support Webpack 5.

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 [email protected] module-to-cdn

Usage with HtmlWebpackPlugin

webpack.config.js

const path = require('path');

const HtmlWebpackPlugin = require('html-webpack-plugin');
const DynamicCdnWebpackPlugin = require('dynamic-cdn-webpack-plugin');

module.exports = {
    entry: {
        'app.js': './src/app.js'
    },

    output: {
        path.resolve(__dirname, './build'),
    },

    plugins: [
        new HtmlWebpackPlugin(),
        new DynamicCdnWebpackPlugin()
    ]
}

app.js

import React from 'react';
import { BrowserRouter } from 'react-router-dom';

// ... do react stuff

webpack --mode=production will generate:

/* simplified webpack build */
[function(module, __webpack_exports__, __webpack_require__) {
    module.exports = React;
}),
(function(module, __webpack_exports__, __webpack_require__) {
    module.exports = ReactRouterDOM;
}),
(function(module, __webpack_exports__, __webpack_require__) {
    var react = __webpack_require__(0);
    var reactRouterDOM = __webpack_require__(1);

    /* ... */
})]
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Webpack App</title>
  </head>
  <body>
    <script type="text/javascript" src="https://unpkg.com/[email protected]/dist/react.min.js"></script><script type="text/javascript" src="https://unpkg.com/[email protected]/umd/react-router-dom.min.js"></script><script src="build/app.js"></script></body>
</html>

Usage with ManifestPlugin

webpack.config.js

const path = require('path');

const ManifestPlugin = require('webpack-manifest-plugin');
const DynamicCdnWebpackPlugin = require('dynamic-cdn-webpack-plugin');

module.exports = {
    entry: {
        'app': './src/app.js'
    },

    output: {
        path.resolve(__dirname, './build'),
    },

    plugins: [
        new ManifestPlugin({
            fileName: 'manifest.json'
        }),
        new DynamicCdnWebpackPlugin()
    ]
}

app.js

import React from 'react';
import { BrowserRouter } from 'react-router-dom';

// ... do react stuff

webpack --mode=production will generate:

/* simplified webpack build */
[function(module, __webpack_exports__, __webpack_require__) {
    module.exports = React;
}),
(function(module, __webpack_exports__, __webpack_require__) {
    module.exports = ReactRouterDOM;
}),
(function(module, __webpack_exports__, __webpack_require__) {
    var react = __webpack_require__(0);
    var reactRouterDOM = __webpack_require__(1);

    /* ... */
})]
{
    "app.js": "app.js",
    "react.js": "https://unpkg.com/[email protected]/dist/react.min.js",
    "react-router-dom.js": "https://unpkg.com/[email protected]/umd/react-router-dom.min.js"
}

API

DynamicCdnWebpackPlugin(options)

webpack.config.js

const DynamicCdnWebpackPlugin = require('dynamic-cdn-webpack-plugin');

module.exports = {
    mode: 'production',
    plugins: [
        new DynamicCdnWebpackPlugin(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.

Contributors

Thanks goes to these wonderful people (emoji key):


Thomas Sileghem

💻 📖 ⚠️

​Faizaan

💬 💻 📖

MICHAEL JACKSON

💡

fedeoo

💻

Kevin Malakoff

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

License

MIT © Thomas Sileghem

版本与发布记录

@effortlessmotion/dynamic-cdn-webpack-plugin 共发布 2 个版本,首次发布于 2021/07/04;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.1latest2021/07/045 年前
5.0.02021/07/045 年前

关于 @effortlessmotion/dynamic-cdn-webpack-plugin 的常见问题

@effortlessmotion/dynamic-cdn-webpack-plugin 是什么?

Dynamically get your dependencies from a cdn rather than bundling them in your app

如何安装 @effortlessmotion/dynamic-cdn-webpack-plugin?

在项目目录运行 npm install @effortlessmotion/dynamic-cdn-webpack-plugin,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:webpack(>=5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@effortlessmotion/dynamic-cdn-webpack-plugin 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/effortlessmotion__dynamic-cdn-webpack-plugin 是否存在。

@effortlessmotion/dynamic-cdn-webpack-plugin 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@effortlessmotion/dynamic-cdn-webpack-plugin 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=10.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@effortlessmotion/dynamic-cdn-webpack-plugin 可以商用吗?

@effortlessmotion/dynamic-cdn-webpack-plugin 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@effortlessmotion/dynamic-cdn-webpack-plugin 的下载量有多少?

根据 npm 官方下载统计,@effortlessmotion/dynamic-cdn-webpack-plugin 在 2026/10/13 – 2026/11/11 这 30 天内被下载 12,763 次,日均约 425 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@effortlessmotion/dynamic-cdn-webpack-plugin 还在维护吗?

最新版本 5.0.1 发布于 2021/07/04(5 年前);至今共发布 2 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/07/04。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。