Skip to content
PluginStats

template-extract-plugin weekly downloads statistics

By BobbyLH · npm · Webpack plugins

Extract a template which with css style tag from html-webpack-plugin result

View on npm Fresh · Dec 6, 2026

template-extract-plugin has 130 recorded weekly downloads on npm, an increase of 251% over the past 30 days, ranking #2572 of 3,247 tracked listings.

Weekly downloads
130
Official API · Dec 5, 2026
7-day growth
+183%
+84 weekly downloads
30-day growth
+251%
+93 weekly downloads
90-day growth
+282%
+96 weekly downloads
Rank
#2572
▲ 61 in 7 days

About template-extract-plugin

template-extract-plugin(webpack模板抽取插件)

NPM downloads npm version install size license

初衷

为了解决前端分享截图痛点,旨在项目 webpack 打包阶段,提取出分享DOM的信息。

从 html-webpack-plugin 中提取 css 和 html,并全局输出 _get_extract_template_ 方法,获取相应的模板。

Note:插件强依赖 html-webpack-plugin,请确保项目中已经安装

使用

安装
npm i --save-dev template-extract-plugin

yarn add -D template-extract-plugin
项目配置
步骤 1:在 index.html/ejs 中添加模板注释
  • <!--template-extract-css--> style 标签插入的位置

  • <!--template-extract-dom--> 动态DOM插入的位置

  • <!--template-extract-js--> JS代码插入的位置

  • <!--template-extract-del-start--> 需要移除的代码块起始标志

  • <!--template-extract-del-end--> 需要移除的代码块结束标志

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <!--template-extract-css-->
    <title>test</title>
    <!--template-extract-del-start-->
    <style>
      .loading{}
    </style>
    <!--template-extract-del-end-->
  </head>
  <body>
    <div id='root'>
      <!--template-extract-del-start-->
      <div class='loading'></div>
      <!--template-extract-del-end-->
      <!--template-extract-dom-->
    </div>
  </body>
  <!--template-extract-js-->
</html>
也可通过配置Plugin的参数,指定js插入的位置
const TemplateExtractPlugin = require('template-extract-plugin');

// ……
new TemplateExtractPlugin({
  /** 将模板注入到单独的 js 文件,而非 html 的内联 script 标签 */
  injectInJs: true,
  /** 自定义文件名,暂只支持 hash 后缀,默认名为 template.extract.js */
  fileName: 'js/snapshot.template.[hash:8].js',
  /** 是否同步加载脚本,默认 false */
  sync: false,
  /** 是否禁用插件执行,默认 false */
  disable: false,
  /** 模板内容是否保留原 html 的 script标签,默认全部移除 */
  scriptTag: false,
  /** 调用模板代码的注入位置,值可以是 head-top、head-bottom、body-top、body-bottom,默认 body-bottom */
  position: 'head-top'
})
步骤 2: 配置你的 webpack.config.js

Note:插件强依赖 css-loader 和 html-webpack-plugin,请优先注册 html-webpack-plugin 保证顺序,注意 TemplateExtractPlugin.loader 和 css-loader 的顺序。

const HtmlWebpackPlugin = require('html-webpack-plugin');
const TemplateExtractPlugin = require('template-extract-plugin');

module.exports = {
  // 省略若干……
  module: {
    rules: [
      {
        test: /.(css|less)$/,
        use: [
          'style-loader',
          TemplateExtractPlugin.loader, // 置于 css-loader 前
          'css-loader',
          'less-loader'
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebpackPlugin({
      title: 'project',
      // ……
    }),
    // ……
    new TemplateExtractPlugin({
      injectInJs: true
    }) // 置于 HtmlWebpackPlugin 后
  ]
};
应用
在代码中获取(以React项目为例)
// src/ShareContent.jsx
export default props => <div>分享的{props.title}内容</div>;
// src/index.jsx
import ReactDOMServer from 'react-dom/server';
import ShareContent from './ShareContent';

const App = () => (
  <div>
    内容若干……
    <button
      onClick={() => {
        const content = ReactDOMServer.renderToString(ShareContent({
          title: '神奇的'
        }));

        if (window._get_extract_template_) {
          let shareDOM;
          if (customStyle) {
            // 自定义了 style 样式
            shareDOM = window._get_extract_template_(content, customStyle);
          } else {
            shareDOM = window._get_extract_template_(content);
          }

          // 接下去的逻辑可能是:发送你的分享DOM到某个node服务,而后用无头浏览器生成图片的相关信息返回给客户端
          // ajax.send(shareDOM);
        }
      }}
    >
      分享按钮
    </button>
  </div>
);

Note:如果你的静态资源 src 地址是自动获取 protocol 的方式(//cdn.xxx.com/image.jpg),可能你需要手动为其添加 protocol,以便它能在无头浏览器中正常执行。

Description from the npm listing.

  • webpack-plugin
  • webpack
  • plugin
  • template-extract-plugin

README badge

Show your rank in a README or on your website. The badge updates automatically.

Charts

Images: 30d · 1y · all time · 1600×900 dark

Adoption over time

template-extract-plugin weekly downloads on npm, last 90 days: 130 weekly downloads as of Dec 5, 2026, +282% over 90 days.template-extract-pluginWeekly downloads on npm · Last 90 days130downloads / week+282% over 90 days020406080100120140Sep 6Sep 21Oct 6Oct 21Nov 5Nov 20Dec 5downloads / weekobservedarchived (Internet Archive)no observationsSep 7, 2026 – Dec 5, 2026 · 90 observations · Updated Dec …pluginstats.com
template-extract-plugin weekly downloads on npm, last 90 days: 130 weekly downloads as of Dec 5, 2026, +282% over 90 days.

7/30/90-day growth

template-extract-plugin weekly downloads growth on npm: +183% over 7 days, +251% over 30 days, +282% over 90 days.template-extract-pluginWeekly downloads growth on npm130downloads / week now7-day growth+84 weekly downloads+183%30-day growth+93 weekly downloads+251%90-day growth+96 weekly downloads+282%Growth vs. nearest observation to each baseline date · Updated Dec 5, 2026pluginstats.com
template-extract-plugin weekly downloads growth on npm: +183% over 7 days, +251% over 30 days, +282% over 90 days.

Ranking history

template-extract-plugin npm ranking history: currently #2572 (by weekly downloads).template-extract-pluginnpm ranking · by weekly downloads · Last 90 days#2572current rank#1800#2000#2200#2400#2600#2800Sep 7Sep 22Oct 7Oct 22Nov 6Nov 21Dec 6rankOct 18, 2026 – Dec 6, 2026 · 33 observations · Updated Dec 5, 2026pluginstats.com
template-extract-plugin npm ranking history: currently #2572 (by weekly downloads).

Listing placement

All npm3,247 listings · 163 pages · 1,083 shown · page 129, #12 (overall #2,572)
All npm: every listing in weekly downloads order

Listing placement

Webpack plugins349 listings · 18 pages · page 9, #3 (overall #163)
Webpack plugins: every listing in weekly downloads order

Filled points are observed values; hollow points come from Internet Archive snapshots of the listing page. Dashed segments span periods with no observations — values between points are not interpolated.

Each band is one page of 20. Weekly downloads on a linear scale. Placement is projected from weekly downloads, so it can differ from the marketplace's own sort order. Hover a dot to see the listing.

Recent observations

Full history (170)
Recent weekly downloads observations for template-extract-plugin
Date (UTC)Weekly downloadsChange vs. previous
130-4
134+38
96-2
98+67
31-6
37-1
38-8
46-8
54-39
93-4
97+2
95-2
97+3
94—

Similar npm Webpack plugins plugins

All 20 template-extract-plugin alternatives

Data source

Weekly downloads (trailing 7 complete days) come from the official npm downloads API. Downloads include CI and mirrors and are not equivalent to installs or users. npm publishes no ratings.

Listing: https://www.npmjs.com/package/template-extract-plugin. First seen Oct 16, 2026; last successful collection Dec 6, 2026. See the methodology.