{"id":19525771,"url":"https://github.com/jae-jae/gulp-split-js-css","last_synced_at":"2025-08-15T22:38:41.753Z","repository":{"id":57259033,"uuid":"90543367","full_name":"jae-jae/gulp-split-js-css","owner":"jae-jae","description":"Gulp split js and css from html,gulp从html中分离出js和css","archived":false,"fork":false,"pushed_at":"2017-05-25T14:54:11.000Z","size":13,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-08-05T09:55:44.405Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jae-jae.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-05-07T15:41:58.000Z","updated_at":"2017-05-07T15:52:10.000Z","dependencies_parsed_at":"2022-08-28T21:01:57.564Z","dependency_job_id":null,"html_url":"https://github.com/jae-jae/gulp-split-js-css","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/jae-jae/gulp-split-js-css","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jae-jae%2Fgulp-split-js-css","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jae-jae%2Fgulp-split-js-css/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jae-jae%2Fgulp-split-js-css/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jae-jae%2Fgulp-split-js-css/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jae-jae","download_url":"https://codeload.github.com/jae-jae/gulp-split-js-css/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jae-jae%2Fgulp-split-js-css/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270639221,"owners_count":24620690,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-15T02:00:12.559Z","response_time":110,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T01:06:59.599Z","updated_at":"2025-08-15T22:38:41.732Z","avatar_url":"https://github.com/jae-jae.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gulp-split-js-css\nGulp split js and css from html,gulp从html中分离出js和css\n## Installation\n```shell\nnpm install gulp-split-js-css\n```\n## Usage 1\n\n`gulpfile.js`\n\n```javascript\nvar gulp = require('gulp');\nvar splitJsCss = require('gulp-split-js-css');\n\n//文件过滤\nvar filter = require('gulp-filter');\n//在html中引用js和css\nvar inject = require('gulp-inject');\n\ngulp.task('default', function() {\n    var stream = gulp.src('./src/index.html')\n        .pipe(splitJsCss({\n        \ttype:['js','css']\n        }));\n\n      var jsFilter = filter('**/*.js');\n      var cssFilter = filter('**/*.css');\n      var htmlFilter = filter('**/*.html');\n\n       var jsStream = stream.pipe(jsFilter);\n       var cssStream = stream.pipe(cssFilter);\n       var htmlStream = stream.pipe(htmlFilter);\n\n        jsStream = jsStream.pipe(gulp.dest('dist/js'));\n        cssStream = cssStream.pipe(gulp.dest('dist/css'));\n\n        return htmlStream.pipe(inject(jsStream))\n        .pipe(inject(cssStream))\n        .pipe(gulp.dest('./dist'));\n\n});\n```\n\n`./src/index.html`\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\t\u003ctitle\u003egulp-split-js-css\u003c/title\u003e\n\u003cstyle type=\"text/css\"\u003e\n\tbody {\n\t    margin:0\n\t}\n\ta:hover, a:active {\n\t    outline:0\n\t}\n\u003c/style\u003e\n\n\u003cstyle type=\"text/css\"\u003e\n\tabbr[title] {\n\t    border-bottom:1px dotted\n\t}\n\u003c/style\u003e\n\n\u003cstyle type=\"text/css\" inline\u003e\n\t.c-box{height:40px;width:100%;margin:150px auto;}\n\u003c/style\u003e\n\n\n\u003c!-- inject:css --\u003e\n\u003c!-- endinject --\u003e\n\n\u003c/head\u003e\n\u003cbody\u003e\n\n\u003cspan\u003eThis is string.\u003c/span\u003e\n\n\u003cscript type=\"text/javascript\"\u003e\n\tvar msg = function(str){\n\t\talert(str);\n\t};\n\u003c/script\u003e\n\n\n\u003cscript type=\"text/javascript\"\u003e\n\tvar str = 'string';\n\tmsg(str);\n\u003c/script\u003e\n\n\n\u003cscript type=\"text/javascript\" inline\u003e\n\tvar str2 = 'string2';\n\tmsg(str2);\n\u003c/script\u003e\n\n\u003c!-- inject:js --\u003e\n\u003c!-- endinject --\u003e\n\n\u003c/body\u003e\n\u003c/html\u003e\n```\n### Out 输出结果\n\n`./dist/index.html`\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n\u003chead\u003e\n\t\u003ctitle\u003egulp-split-js-css\u003c/title\u003e\n\n\u003cstyle type=\"text/css\" inline=\"\"\u003e\n\t.c-box{height:40px;width:100%;margin:150px auto;}\n\u003c/style\u003e\n\n\n\u003c!-- inject:css --\u003e\n\u003clink rel=\"stylesheet\" href=\"/dist/css/index.css\"\u003e\n\u003c!-- endinject --\u003e\n\n\u003c/head\u003e\n\u003cbody\u003e\n\n\u003cspan\u003eThis is string.\u003c/span\u003e\n\n\u003cscript type=\"text/javascript\" inline=\"\"\u003e\n\tvar str2 = 'string2';\n\tmsg(str2);\n\u003c/script\u003e\n\n\u003c!-- inject:js --\u003e\n\u003cscript src=\"/dist/js/index.js\"\u003e\u003c/script\u003e\n\u003c!-- endinject --\u003e\n\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n`./dist/js/index.js`\n\n```javascript\n\tvar msg = function(str){\n\t\talert(str);\n\t};\n\n\tvar str = 'string';\n\tmsg(str);\n```\n\n`./dist/css/index.css`\n\n```css\n\tbody {\n\t    margin:0\n\t}\n\ta:hover, a:active {\n\t    outline:0\n\t}\n\n\tabbr[title] {\n\t    border-bottom:1px dotted\n\t}\n```\n\n## Usage 2\n```javascript\nvar gulp = require('gulp');\n\nvar sjc = require('gulp-split-js-css');\n\n//文件过滤\nvar filter = require('gulp-filter');\n//在html中引用js和css\nvar inject = require('gulp-inject');\n\nvar foreach = require('gulp-foreach');\n\ngulp.task('default', function() {\n\n  return gulp.src('./src/*.html')\n    .pipe(foreach(function(streamX, file) {\n\n      var stream = streamX.pipe(sjc({\n        type: ['js', 'css']\n      }));\n\n      var jsFilter = filter('**/*.js');\n      var cssFilter = filter('**/*.css');\n      var htmlFilter = filter('**/*.html');\n\n      var jsStream = stream.pipe(jsFilter);\n      var cssStream = stream.pipe(cssFilter);\n      var htmlStream = stream.pipe(htmlFilter);\n\n      jsStream = jsStream.pipe(gulp.dest('dist/js'));\n      cssStream = cssStream.pipe(gulp.dest('dist/css'));\n\n      return htmlStream.pipe(inject(jsStream))\n        .pipe(inject(cssStream));\n\n    })).pipe(gulp.dest('./dist'));\n\n});\n\n```\n\n## Parameters 参数\n\n### type \nType:`String`|`Array`,split type `js` or `css`,defalut value `['js','css']`\n指定分离类型，可以只分离出js或者css，默认都分离\n\n**注**:标签加上`inline`属性后,将被跳过,不会被分离出来.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjae-jae%2Fgulp-split-js-css","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjae-jae%2Fgulp-split-js-css","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjae-jae%2Fgulp-split-js-css/lists"}