html-webpack-cdn-plugin
v0.2.0
Published
cdn in webpack
Downloads
35
Maintainers
Readme
Html-webpack-cdn-plugin
cdn in webpack
Useage
Dependencies
cdn-loader You NEAD Install
cdn-loader
andhtml-webpack-plugin
Install
- Run
npm i -D html-webpack-cdn-plugin
in your project folder - Add
var HtmlWebpackCdnPlugin = require('html-webpack-cdn-plugin')
towebpack.config.js
file - Add
new HtmlWebpackCdnPlugin(config)
towebpack.config.js
file (plugins
) - Also you need cdn-loader and html-webpack-plugin
Support
css and js files https://cdnjs.com
Config
Example
// webpack.config.js
var config = {
host: "https://cdnjs.cloudflare.com/ajax/libs",
cdn: {
js: "https://cdnjs.cloudflare.com/ajax/libs",
css: "https://cdnjs.cloudflare.com/ajax/libs"
}
}
var webpackConfig = {
entry: 'index.js',
output: {
path: 'dist',
filename: 'index_bundle.js'
},
plugins: [
new HtmlWebpackCdnPlugin(config),
new HtmlWebpackPlugin()
]
};
// index.js
var $ = require("[email protected]")
// Now you can use it
$('.app')
require("[email protected]&type=css")
// cdn-loader
// .......more code
Then
<!DOCTYPE html>
<html>
<head>
<title>app</title>
<link rel="stylesheet" href="http://cdn.bootcss.com/normalize/4.2.0/normalize.min.css">
</head>
<body>
<div class="app"></div>
<!-- more code -->
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="index_bundle.js"></script>
</html>