头图

inject-inner-webpack-plugin Chinese document

福尔摩松
中文

inject-inner-webpack-plugin

<hr/>
A web page package plugin that injects internal script sources into the HTML file output by the HTML web package plugin

installation

<hr/>

npm install --save-dev inject-inner-webpack-plugin

Example

<hr/>

webpack.config.js
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InjectInnerWebpackPlugin = require('inject-inner-webpack-plugin');

module.exports = {
    entry: {
        index: './index.js',
    },
    plugins: [
        new HtmlWebpackPlugin({
            template: 'index.html',
        }),
        new InjectInnerWebpackPlugin(HtmlWebpackPlugin),
    ],
};
index.html
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Webpack App</title>
    <!-- 此脚本标记将被输出html中的内部源代码替换 -->
    <script src="./inner.js?__inline"></script>
  </head>
  <body>
  </body>
</html>

This will generate a file dist/index.html containing the following

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Webpack App</title>
    <script>
        // inner.js捆绑内容
    </script>
  </head>
  <body>
      <script src="index.js"></script>
  </body>
</html>

The entry in webpack.config.js should be Object.
Only handle HtmlWebpackPlugin instances with template options.

Options

<hr/>
HtmlWebpackPlugin must be passed to the first parameter, the second parameter is optional, for example:

const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');

new InjectInnerWebpackPlugin(HtmlWebpackPlugin, {
    context: path.resolve(__dirname, '..'),
});

The allowed values of the second parameter are as follows:

nameTypes ofDefaultsDescription
context{String}: stringWebpack ContextHow to use src/inner.js? Relative path such as __inline, the path will be relative to the context
isRemainBundle{Boolean}: Boolean valuefalseIf true, the internal block to be output is reserved.
scriptTag{Function}: function``Customize internal content output
template{String&Array}: String & Array``Specify the template to be injected
阅读 341
0 声望
0 粉丝
0 条评论
你知道吗?

0 声望
0 粉丝
宣传栏