目录

webpack-auto-cdn-plugin

Webpack plugin to automatically extract dependencies and reference them via CDN.

This plugin will scan your dependencies and devDependencies, extract those suitable to be hosted on CDN via lib/hints.js and add them to externals, a <script> tag will be added to your html-webpack-plugin generated HTML file so that these dependencies can be referenced via CDN.

Usage

This plugin requires html-webpack-plugin@4.x to work.

// webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const AutoCDNPlugin = require('../index');

module.exports = {
    mode: 'development',
    context: __dirname,
    entry: path.join(__dirname, 'index.js'),
    output: {
        path: path.join(__dirname, 'dist'),
    },
    plugins: [
        new HtmlWebpackPlugin(),
        new AutoCDNPlugin({cwd: __dirname}),
    ],
};

Options

  • {string} cwd: Current working directory where package.json of your project is.

Play It

cd demo
yarn install
webpack --config=webpack.config.js

Have a look at dist/index.html and dist/main.js, all dependencies are removed from dist javascript, <script> tags are generated automatically.

关于
543.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号