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

link-pre-webpack-plugin

v1.0.6

Published

该插件提供了更细致化的插入 link-pre 的功能,使用的时候需要将该插件放在其他的 html-template-plugin 也就是 html 模板处理的插件下方,并传入和 html 模板的插件相同的 filename 即可使用

Downloads

9

Readme

link-pre-webpack-plugin

介绍

该插件提供了更细致化的插入 link-pre 的功能,使用的时候需要将该插件放在其他的 html-template-plugin 也就是 html 模板处理的插件下方,并传入和 html 模板的插件相同的 filename 即可使用

经测试,能够使用在 html-webpack-plugin、web-webpack-plugin html 模板插件后使用

想像一个场景,多入口单页面文件,每个对应一个 template,在输入账号密码的页面可以预先加载登陆后的页面的资源,比如 login 页面增加了 preload:main,在输入完密码之后说不定 main 资源已经加载完成,登陆之后若需要请求 main 的 js 文件,直接通过 304 缓存中获取即可)

使用

插件专注处理一个 html 文件,若想对多个文件进行操作请创建多个实例并传入不同的 filename 即可

插件可以适配 optimization.splitChunks 和 mini-css-extract-plugin

参数说明

  • filename:String html 文件的名称,一定要和传给其他 html 模板处理插件的 filename 相同
  • preload:Object
    • js:Object
      • hrefs:Array
        • 数字元素可以是一个 string,代表了资源的 CDN 地址
          hrefs: ['https://cdn.bootcss.com/lodash.js/4.17.12-pre/lodash.min.js', ...]
        • 也可以传入更细致的参数,比如
          hrefs: [
            {
              href: 'https://cdn.bootcss.com/jquery/3.3.1/jquery.js',
              attrs: [{ name: 'media', value: '(max-width: 600px)' }]
            }
          ]
          如上传入 attrs,插件内部会将其合并生成 link-dom,如上参数设置可以在 media < 600px 的时候再加载
      • chunks:Array
        • 数字元素可以是一个 string,代表了某一入口的 entry name,或者是 splitChunksname
          chunks: ['common-js', ...]
        • 也可以和上面一样传入更细致的参数,比如
          chunks: [
            {
              chunk: 'main', // 代表了另一个入口的 entry name
              attrs: [{ name: 'media', value: '(max-width: 600px)' }]
            }
          ]
    • css:Object
      • hrefs:Array
        • 和 js 类似
      • chunks:Array
        • 和 js 类似
  • prefetch:Object
    • 和 preload 类似

参考配置

new LinkPreWebpackPlugin({
  filename: 'login.html',
  preload: {
    js: {
      hrefs: [
        { href: 'https://cdn.bootcss.com/lodash.js/4.17.12-pre/lodash.min.js' },
        {
          href: 'https://cdn.bootcss.com/jquery/3.3.1/jquery.js',
          attrs: [{ name: 'media', value: '(max-width: 600px)' }]
        }
      ],
      chunks: [
        { chunk: 'common-js' },
        {
          chunk: 'main',
          attrs: [{ name: 'media', value: '(max-width: 600px)' }]
        }
      ]
    },
    css: {
      hrefs: [
        { href: 'https://cdn.bootcss.com/animate.css/3.7.0/animate.min.css' },
        {
          href: 'https://cdn.bootcss.com/hover.css/2.3.1/css/hover-min.css',
          attrs: [{ name: 'media', value: '(max-width: 600px)' }]
        }
      ],
      chunks: [
        {
          chunk: 'common-style',
          attrs: [{ name: 'media', value: '(max-width: 600px)' }]
        }
      ]
    }
  },
  prefetch: {
    js: {
      hrefs: [
        { href: 'https://cdn.bootcss.com/lodash.js/4.17.12-pre/lodash.min.js' },
        { href: 'https://cdn.bootcss.com/jquery/3.3.1/jquery.js' }
      ],
      chunks: [{ chunk: 'common-js' }, { chunk: 'main' }]
    },
    css: {
      hrefs: [
        { href: 'https://cdn.bootcss.com/animate.css/3.7.0/animate.min.css' },
        { href: 'https://cdn.bootcss.com/hover.css/2.3.1/css/hover-min.css' }
      ],
      chunks: [{ chunk: 'common-style' }]
    }
  }
})

TODO

  • css 的 publicPath 该怎么处理
  • 能不能不使用 indexOf 作为判断依据,因为当公共模块的文件名和其他模块文件名重复的时候,依赖会加载错误
  • 热更新 html,在 afterCompile 的时候把 html 添加监视热更新依赖
  • 测试开发环境(webpack-dev-server)下是否能使用
  • 加入判断参数是否传入正确的机制