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 🙏

© 2026 – Pkg Stats / Ryan Hefner

gulp-split-js-css

v1.0.8

Published

Gulp split js and css from html,gulp从html中分离出js和css

Readme

gulp-split-js-css

Gulp split js and css from html,gulp从html中分离出js和css

Installation

npm install gulp-split-js-css

Usage 1

gulpfile.js

var gulp = require('gulp');
var splitJsCss = require('gulp-split-js-css');

//文件过滤
var filter = require('gulp-filter');
//在html中引用js和css
var inject = require('gulp-inject');

gulp.task('default', function() {
    var stream = gulp.src('./src/index.html')
        .pipe(splitJsCss({
        	type:['js','css']
        }));

      var jsFilter = filter('**/*.js');
      var cssFilter = filter('**/*.css');
      var htmlFilter = filter('**/*.html');

       var jsStream = stream.pipe(jsFilter);
       var cssStream = stream.pipe(cssFilter);
       var htmlStream = stream.pipe(htmlFilter);

        jsStream = jsStream.pipe(gulp.dest('dist/js'));
        cssStream = cssStream.pipe(gulp.dest('dist/css'));

        return htmlStream.pipe(inject(jsStream))
        .pipe(inject(cssStream))
        .pipe(gulp.dest('./dist'));

});

./src/index.html

<!DOCTYPE html>
<html>
<head>
	<title>gulp-split-js-css</title>
<style type="text/css">
	body {
	    margin:0
	}
	a:hover, a:active {
	    outline:0
	}
</style>

<style type="text/css">
	abbr[title] {
	    border-bottom:1px dotted
	}
</style>

<style type="text/css" inline>
	.c-box{height:40px;width:100%;margin:150px auto;}
</style>


<!-- inject:css -->
<!-- endinject -->

</head>
<body>

<span>This is string.</span>

<script type="text/javascript">
	var msg = function(str){
		alert(str);
	};
</script>


<script type="text/javascript">
	var str = 'string';
	msg(str);
</script>


<script type="text/javascript" inline>
	var str2 = 'string2';
	msg(str2);
</script>

<!-- inject:js -->
<!-- endinject -->

</body>
</html>

Out 输出结果

./dist/index.html

<!DOCTYPE html>
<html>
<head>
	<title>gulp-split-js-css</title>

<style type="text/css" inline="">
	.c-box{height:40px;width:100%;margin:150px auto;}
</style>


<!-- inject:css -->
<link rel="stylesheet" href="/dist/css/index.css">
<!-- endinject -->

</head>
<body>

<span>This is string.</span>

<script type="text/javascript" inline="">
	var str2 = 'string2';
	msg(str2);
</script>

<!-- inject:js -->
<script src="/dist/js/index.js"></script>
<!-- endinject -->

</body>
</html>

./dist/js/index.js

	var msg = function(str){
		alert(str);
	};

	var str = 'string';
	msg(str);

./dist/css/index.css

	body {
	    margin:0
	}
	a:hover, a:active {
	    outline:0
	}

	abbr[title] {
	    border-bottom:1px dotted
	}

Usage 2

var gulp = require('gulp');

var sjc = require('gulp-split-js-css');

//文件过滤
var filter = require('gulp-filter');
//在html中引用js和css
var inject = require('gulp-inject');

var foreach = require('gulp-foreach');

gulp.task('default', function() {

  return gulp.src('./src/*.html')
    .pipe(foreach(function(streamX, file) {

      var stream = streamX.pipe(sjc({
        type: ['js', 'css']
      }));

      var jsFilter = filter('**/*.js');
      var cssFilter = filter('**/*.css');
      var htmlFilter = filter('**/*.html');

      var jsStream = stream.pipe(jsFilter);
      var cssStream = stream.pipe(cssFilter);
      var htmlStream = stream.pipe(htmlFilter);

      jsStream = jsStream.pipe(gulp.dest('dist/js'));
      cssStream = cssStream.pipe(gulp.dest('dist/css'));

      return htmlStream.pipe(inject(jsStream))
        .pipe(inject(cssStream));

    })).pipe(gulp.dest('./dist'));

});

Parameters 参数

type

Type:String|Array,split type js or css,defalut value ['js','css'] 指定分离类型,可以只分离出js或者css,默认都分离

:标签加上inline属性后,将被跳过,不会被分离出来.