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

fis3-postpackager-robot

v1.10.7

Published

fis按需异步加载打包工具

Downloads

38

Readme

fis3-postpackager-robot

  • 适用于**'按需异步加载'**的情况
  • 需搭配 https://github.com/pup/mod 中的mod.js,请不要用官方提供的mod.js
  • 同目录下可以有多个html,打包结果完全互不干扰,会为每个入口文件(.html)单独生成 resourcemap,并替换入口文件中的占位符<!--DEPENDENCIES_INJECT_PLACEHOLDER-->
  • 目前注入格式仅支持 mod/commonjs 需求

		src/
			index.html ;打包结果只跟index.html有关
			feedback.html ;打包结果与index.html毫无关系

打包思路说明

  • 文件依赖关系图:
    1. @require 表示直接依赖关系, 同fis3中的使用方法一样
    2. @require.async 表示异步加载, 同fis3中的使用方法一样

robot打包思路

  • ** 如图所示,自动以require.async(deps, callback)为分界点** 分别将 index.jsxtable.jsx及其所依赖的文件打包合并成四个最终文件(js和cs各俩个,如下表所示)
  • 打包后的文件包含关系

打包结果|打包结果包含的文件 ------------ | ------------- pkg_index_0.css|index.scss, footer.scss, header.scss pkg_index_0.js|header.jsx, footer.jsx, index.jsx pkg_table_1.js|table.jsx, tableHeader.jsx pkg_table_1.css|table.scss, tableHeader.scss

配置说明

	
	fis.match('::package', {
		//默认配置如下
		postpackager: fis.plugin('robot', {
			  // 脚本占位符
			  scriptPlaceHolder: '<!--SCRIPT_PLACEHOLDER-->',
			
			  // 样式占位符
			  stylePlaceHolder: '<!--STYLE_PLACEHOLDER-->',
			
			  // 依赖关系脚本注入位置占位符,注入结果格式仅支持 mod/commonjs
			  resourceMapPlaceHolder: '<!--DEPENDENCIES_INJECT_PLACEHOLDER-->', 
			  
			  // 依赖分析的入口后缀文件名
			  entryExt: '.html',

			  // 打包结果自定义路径, 同fis中的release意义一样
			  releasePathPrefix: '/',

			  // 打包路径和应用路径分开, 同fis中的 uri 意义一样
			  urlPrefix: '/'
		})
	}

注意:

打包生成的文件同样会匹配fis-conf.js中定义的配置规则 比如 生成的文件名是./pkg/pkg-index-0.css;如果 fis-conf.js 中定义了

		
		fis.match("**.css", {...}) //那么打包的结果pkg-index-0.css就会匹配到这条规则。

示例

index.html


	<!DOCTYPE html>
	<html>
	  <head>
	    <meta charset="utf-8">
	    <title></title>
	    <!--STYLE_PLACEHOLDER-->
	  </head>
	  <body>
	    <script type="text/javascript" src="/static/mod.js"></script> <!--必须-->
	    <!--SCRIPT_PLACEHOLDER-->
	    <!--DEPENDENCIES_INJECT_PLACEHOLDER-->
	    <script type="text/javascript">
	    	require('./index.jsx')
	    </script>
	  </body>
	</html>

文件: index.jsx

	
	// @require './index.scss'
	var header = import('./header.jsx');
	var footer = import('./footer.jsx');
	
	function someFunction() {
		require.async('./table.jsx', function({table: default}){
			//use table here
		})
	}
	someFunction(); //需要的时候执行该方法就会执行异步加载

文件: header.jsx


	//@require './header.scss'
	export default function() {console.log('>> header.scss')}

文件: table.jsx


	//@require './table.scss'
	export default function() {console.log('>> table.scss')}

2018-03-22 更新

  • 修复了多个打包多个html入口文件时,最终生成的pkg.js/css不准确的bug