https://github.com/ecomfe/webpack-auto-cdn-plugin
Webpack plugin to automatically extract dependencies and reference them via CDN
https://github.com/ecomfe/webpack-auto-cdn-plugin
Last synced: 11 months ago
JSON representation
Webpack plugin to automatically extract dependencies and reference them via CDN
- Host: GitHub
- URL: https://github.com/ecomfe/webpack-auto-cdn-plugin
- Owner: ecomfe
- License: mit
- Created: 2019-08-06T05:58:42.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2023-01-07T08:27:42.000Z (over 3 years ago)
- Last Synced: 2025-05-25T08:05:23.157Z (about 1 year ago)
- Language: JavaScript
- Size: 3.46 MB
- Stars: 10
- Watchers: 10
- Forks: 1
- Open Issues: 36
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 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](lib/hints.js) and add them to `externals`, a `` 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.
```javascript
// 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
```shell
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.