Skip to content

denghui1010/cdn-html-webpack-plugin

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🇨🇳中文 | 🇬🇧English

cdn-html-webpack-plugin

npm node

About

Make the generated index.html file use the cdn host to load resources.

Requirement

This plugin depends on html-webpack-plugin

Installation

npm install cdn-html-webpack-plugin --save-dev

Usage

1. Absolute path mode. All relative paths in the index.html file will be replaced with the configured absolute path.

const CdnHtmlWebpackPlugin = require("cdn-html-webpack-plugin");

new HtmlWebpackPlugin({
    cdn: {
        cdnpath: "http://cdnhost"
    }
}),
new CdnHtmlWebpackPlugin()

in

<!DOCTYPE html>
<html>
    <head>
        <link href=./static/css/app.a55284ea60abd800fe5c0239b78ec1d4.css rel=stylesheet>
    </head>
    <body>
        <div id=app></div>
        <script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js> </script>
    </body> 
</html>

out

<!DOCTYPE html>
<html>
    <head>
        <link href=http://cdnhost/static/css/app.a55284ea60abd800fe5c0239b78ec1d4.css rel=stylesheet>
    </head>
    <body>
        <div id=app></div>
        <script type=text/javascript src=http://cdnhost/static/js/manifest.3ad1d5771e9b13dbdad2.js> </script>
    </body> 
</html>

2. Base tag mode. A <base> tag will be injected on the top of the <head> tag in the index.html file. Then the browser will use the configured path to resolve all relative paths.

const CdnHtmlWebpackPlugin = require("cdn-html-webpack-plugin");

new HtmlWebpackPlugin({
    cdn: {
        cdnbase: "http://cdnhost"
    }
}),
new CdnHtmlWebpackPlugin()

in

<!DOCTYPE html>
<html>
    <head>
        <link href=./static/css/app.a55284ea60abd800fe5c0239b78ec1d4.css rel=stylesheet>
    </head>
    <body>
        <div id=app></div>
        <script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js> </script>
    </body> 
</html>

out

<!DOCTYPE html>
<html>
    <head>
        <base src="http://cdnhost"> </base>
        <link href=./static/css/app.a55284ea60abd800fe5c0239b78ec1d4.css rel=stylesheet>
    </head>
    <body>
        <div id=app></div>
        <script type=text/javascript src=./static/js/manifest.3ad1d5771e9b13dbdad2.js> </script>
    </body> 
</html>

License

MIT

About

Make the generated index.html file use the cdn host to load resources.

Resources

License

Stars

Watchers

Forks

Packages

No packages published