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

gulp-based-front-end-preprocessor

v1.0.7

Published

used to package,minify and hash css/js file

Downloads

6

Readme

gulp-based-front-end-preprocessor

You can submit bugs here

Install

npm install gulp-based-front-end-preprocessor

This preprocessor does the following work:

  1. concat files according to packages config
  2. minify js and css files
  3. add hash postfix to js/css file names
  4. update references in corresponding html-like files(developed for html and jsp, but should be OK on other html-like files)
  5. copy all but jsp/html files from source_dir to output_dir

API

NOTICE: All file paths mentioned below are paths relative to source_dir

source_dir(required)

The directory of source files

output_dir(required)

The output directory

packages(optional)

default is {}, this object is organized as below:

  • first level is html-like file path
  • second level is concated js/css file path
  • third level is js/css files to be concated

Example

{
	"test/jsp/test.jsp": {
		"test/js/test-all.js": [
			"test/js/test.js",
			"test/js/test01.js",
			"test/js/test02.js",
			"test/js/test03.js",
			"test/js/test04.js",
			"test/js/test05.js"
		],
		"test/js/test-lib.js": [
			"common/js/jquery-ui.min.js",
			"common/js/comboboxWidget.js"
		]
	},
	"order/jsp/order.jsp": {
		"order/js/order-all.css": [
			"order/js/order.css",
			"order/js/order01.css",
			"order/js/order02.css",
			"order/js/order03.css",
			"order/js/order04.css",
			"order/js/order05.css"
		],
		"order/js/order-lib.css": [
			"common/js/jquery-ui.min.css",
			"common/js/comboboxWidget.css"
		]
	}
}

requireTypeAttributeInJsTag(optional)

Default is false. If set to true, only script tags with type="text/javascript" attribute will be considered as legal, tags like<script src="path/to/js/file"></script> will be be ignored

css_js_files(optional)

Glob strings of to be processed js/css files. Default is ["**/*.js", "**/*.css"]. About Glob string, you can reference vinyl-fs for detail.

html_like_files(optional)

Glob strings of to be processed html-like files. Default is ["**/*.jsp", "**/*.html"]. About Glob string, you can reference vinyl-fs for detail.

convertRelativePathToReferenceUrl(optional)

Default is function(str) {return str;}. If path of js/css file is "test/js/test.js" while the reference url in html-like file is <script type="text/javascript" src="./test/js/test.js"></script>, then you can set convertRelativePathToReferenceUrl to: function(relativePath) { return "./" + relativePath;}.

NOTICE: convertRelativePathToReferenceUrl and convertReferenceUrlToRelativePath should appear in pairs

convertReferenceUrlToRelativePath(optional)

Default is function(str) {return str;}.

If path of js/css file is "test/js/test.js" while the reference url in html-like file is <script type="text/javascript" src="./test/js/test.js"></script>, then you can set convertRelativePathToReferenceUrl to: function(referenceUrl) {return referenceUrl.replace(/^(\.\/)?(.*)$/, "$2");}

NOTICE: convertRelativePathToReferenceUrl and convertReferenceUrlToRelativePath should appear in pairs

Simple Example

var processor = require("gulp-based-front-end-preprocessor");
var config = {
	source_dir: "source_dir",
	output_dir: "test"
}
processor.execute(config);

The code above does the following work:

  1. minify js and css files
  2. add hash postfix to js/css file names
  3. update references in corresponding jsp/html files
  4. copy all but jsp/html files from source_dir to output_dir

Full Featured Example

var processor = require("gulp-based-front-end-preprocessor");
var config = {
	packages: {
		"test/jsp/test.jsp": {
			"test/js/test-all.js": [
				"test/js/test.js",
				"test/js/test01.js",
				"test/js/test02.js",
				"test/js/test03.js",
				"test/js/test04.js",
				"test/js/test05.js"
			],
			"test/js/test-lib.js": [
				"common/js/jquery-ui.min.js",
				"common/js/comboboxWidget.js"
			]
		},
		"order/jsp/order.jsp": {
			"order/js/order-all.css": [
				"order/js/order.css",
				"order/js/order01.css",
				"order/js/order02.css",
				"order/js/order03.css",
				"order/js/order04.css",
				"order/js/order05.css"
			],
			"order/js/order-lib.css": [
				"common/js/jquery-ui.min.css",
				"common/js/comboboxWidget.css"
			]
		}
	},
	source_dir: "source_dir",
	output_dir: "test",
	requireTypeAttributeInJsTag: true,
	css_js_files: ["**/*.js", "**/*.css"],
	html_like_files: "**/*.html",
	//The following convertRelativePathToReferenceUrl and convertReferenceUrlToRelativePath works in this case:
	//if the reference in html-like files looks like: "./test/js/test.js",
	//while the real webRoot-relative path looks like "test/js/test.js"
	convertRelativePathToReferenceUrl: function(relativePath) {
		return "./" + relativePath;
	},
	convertReferenceUrlToRelativePath: function(referenceUrl) {
		return referenceUrl.replace(/^(\.\/)?(.*)$/, "$2");
	}
}
processor.execute(config);