npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

build-html-webpack-plugin

v0.1.2

Published

简易版的`html-webpack-plugin`

Downloads

3

Readme

build-html-webpack-plugin

简易版的html-webpack-plugin

功能说明

  • 支持自动替换bundle的实际访问地址

  • 支持搭配webpack-dev-server使用, 并可选择性开启html监听自动刷新

使用说明

// webpack.config.js
var BuildHtmlWebpackPlugin = require('build-html-webpack-plugin')
module.exports = {
  // ...
  plugins: [new BuildHtmlWebpackPlugin({
    tplPath: './outTpl',
    outPath: './'
  })];
}

参数说明:

new BuildHtmlWebpackPlugin(options);

// options.tplPath  模板的目录(目录下所有html文件批量处理), 可以是绝对路径, 可以是相对于执行webpack命令的相对路径(process.cwd())
// option.outPath  html文件的输出目录, 可以是绝对路径, 可以是相对于执行webpack命令的相对路径(process.cwd())

模板示例:

<!DOCTYPE html>
<html>
<head>
  <title>Hello world</title>
  <meta name="keywords" content="">
  <meta name="description" content="">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <meta name="format-detection" content="telephone=no">
  <meta name="viewport" content="initial-scale=1, width=device-width, maximum-scale=1, minimum-scale=1, user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-touch-fullscreen" content="yes">
  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">
  <!-- nunjucks 模板变量语法 -->
  <!-- module["bundleName.js"] or module["bundleNamename.css"] 替换实际bundle的实际访问地址 -->
  <link rel="stylesheet" href="{{ module["app.css"] }}">
</head>
<body>
  <div id="main"></div>
  <!-- nunjucks 模板变量语法 -->
  <!-- module["bundleName.js"] or module["bundleNamename.css"] 替换实际bundle的实际访问地址 -->
  <script src="{{ module["app.js"] }}"></script>
</body>
</html>

搭配webpack-dev-server使用

希望开启修改html模板的时候启用liveReload吗?

  • webpack.config.js 按上述配置使用插件

  • webpack.config.js中的entry, 添加插件的client

    var config = require("./webpack.config.js");
    config.entry.app.unshift("webpack-dev-server/client?http://localhost:8080/");
    config.entry.app.unshift("build-html-webpack-plugin/lib/client?http://localhost:8080/");
    var compiler = webpack(config);
    var server = new WebpackDevServer(compiler, {...});
    compiler._server = server; // 一定要加这一句
    server.listen(8080);
  • cli添加环境变量WATCH=true

    $ WATCH=true your-server # can be webpack-dev-server or your server-cli