1.0.0 • Published 5 years ago

content-inject-plugin v1.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

content-inject-plugin

a plugin for html-webpack-plugin,which can inject static file content into html page

Usage

var ContentInjectPlugin = require('./plugins/contentInjectPlugin');

new ContentInjectPlugin({
    contents:{
        content: 'this is inject content',
        rem: function(){
            return fs.readFileSync('./src/static/js/rem.js',{encoding:'utf8'});
        },
        other: 'other file content'
    },
    replaceMode: 'all',
    memo: true
})

in template

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>template</title>
        <meta charset="utf-8">
        <meta name="hotcss" content="design-width=750">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta content="black" name="apple-mobile-web-app-status-bar-style">
        <meta content="telephone=no" name="format-detection">
        <script>
        {{{__rem__}}}
        </script>
        <script>
        {{{__other__}}}
        </script>
    </head>
    <body>
        <div id="app">
        </div>
        {{{__other__}}}
    </body>
</html>

Params

ParameterTypeDefaultOptionsDescription
contentsarraythe content's array, which key used by tag in template, like {{{__key__}}}, support function to get content
replaceModestringallall,firstreplace all matches or the first match
memobooleanmemorize the content or not

Note

In tempalte, content tag, which want to inject into head, must use legal tag like wrapped, if not, it will be injected into body.

1.0.0

5 years ago