{"id":13527815,"url":"https://github.com/jwvdiermen/grunt-include-source","last_synced_at":"2025-04-01T10:32:50.444Z","repository":{"id":9550023,"uuid":"11457001","full_name":"jwvdiermen/grunt-include-source","owner":"jwvdiermen","description":"Include lists of files into your source files automatically.","archived":false,"fork":false,"pushed_at":"2017-04-06T07:02:22.000Z","size":137,"stargazers_count":68,"open_issues_count":10,"forks_count":30,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-11T00:08:45.957Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"HTML","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jwvdiermen.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-MIT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-07-16T18:32:54.000Z","updated_at":"2021-08-31T00:46:18.000Z","dependencies_parsed_at":"2022-08-28T03:00:41.577Z","dependency_job_id":null,"html_url":"https://github.com/jwvdiermen/grunt-include-source","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwvdiermen%2Fgrunt-include-source","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwvdiermen%2Fgrunt-include-source/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwvdiermen%2Fgrunt-include-source/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jwvdiermen%2Fgrunt-include-source/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jwvdiermen","download_url":"https://codeload.github.com/jwvdiermen/grunt-include-source/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246625637,"owners_count":20807793,"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","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-08-01T06:02:02.725Z","updated_at":"2025-04-01T10:32:50.136Z","avatar_url":"https://github.com/jwvdiermen.png","language":"HTML","funding_links":[],"categories":["HTML"],"sub_categories":[],"readme":"# grunt-include-source\n\n\u003e Include your sources into your HTML files automatically.\n\n## No longer maintained!\n\n**NOTE** This repository is no longer actively maintained, but pull requests will still be handled.\n\n## Getting Started\nThis plugin requires Grunt `~0.4.4`\n\nIf you haven't used [Grunt](http://gruntjs.com/) before, be sure to check out the [Getting Started](http://gruntjs.com/getting-started) guide, as it explains how to create a [Gruntfile](http://gruntjs.com/sample-gruntfile) as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:\n\n```shell\nnpm install --save-dev grunt-include-source\n```\n\nOnce the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:\n\n```js\ngrunt.loadNpmTasks('grunt-include-source');\n```\n\n## The \"includeSource\" task\n\n### Overview\nIn your project's Gruntfile, add a section named `includeSource` to the data object passed into `grunt.initConfig()`.\n\n```js\ngrunt.initConfig({\n  includeSource: {\n    options: {\n      // Task-specific options go here.\n    },\n    your_target: {\n      // Target-specific file lists and/or options go here.\n    },\n  },\n})\n```\n\n### Options\n\n#### options.basePath\nType: `String` or `Array[String]`\nDefault value: `''`\n\nThe base path to use when expanding files.\nCan be an array to support expanding files from multiple paths.\n\n#### options.baseUrl\nType: `String`\nDefault value: `''`\n\nThe base URL to use for included files in the final result.\nFor example, setting `baseUrl` to `public/` will result in files being included from `public/path/to/your/file`.\n\n#### options.templates\nType: `Object`\n\nThe templates for sources included in `html`, `haml`, `jade`, `pug`, `scss`, `less`, `ts` files. Definition of single template overrides its default equivalent only.\n\nExample:\n```js\nincludeSource: {\n  options: {\n    basePath: 'app',\n    baseUrl: 'public/',\n    templates: {\n      html: {\n        js: '\u003cscript src=\"{filePath}\"\u003e\u003c/script\u003e',\n        css: '\u003clink rel=\"stylesheet\" type=\"text/css\" href=\"{filePath}\" /\u003e',\n      },\n      haml: {\n        js: '%script{src: \"{filePath}\"}/',\n        css: '%link{href: \"{filePath}\", rel: \"stylesheet\"}/'\n      },      \n      jade: { // Or pug\n        js: 'script(src=\"{filePath}\", type=\"text/javascript\")',    \n        css: 'link(href=\"{filePath}\", rel=\"stylesheet\", type=\"text/css\")'\n      },\n      scss: {\n        scss: '@import \"{filePath}\";',\n        css: '@import \"{filePath}\";',\n      },\n      less: {\n        less: '@import \"{filePath}\";',\n        css: '@import \"{filePath}\";',\n      },\n      ts: {\n        ts: '/// \u003creference path=\"{filePath}\" /\u003e'\n      }\n    }\n  },\n  myTarget: {\n    files: {\n      'dist/index.html': 'app/index.tpl.html'\n    }\n  }\n}\n```\n\nAs it was mentioned above, it is possible to override only necessary templates.\n\n#### options.typeMappings\nType: `Object`\n\nMap types that are not supported but have the same syntax as an existing type. For example:\n```js\n\nincludeSource: {\n  options: {\n    typeMappings: {\n      // CSHTML files uses the same syntax as HTML files.\n      'cshtml': 'html',\n      // LESS files use the same syntax as SCSS files.\n      'less': 'scss'\n    }\n  }\n}\n```\n\n#### options.rename\nType: `function`\n\nA way of returning a custom filepath.\n\nSee [grunt.file.expandMapping](http://gruntjs.com/api/grunt.file#grunt.file.expandmapping).\nIf specified, this function will be responsible for returning the final dest filepath. By default, it joins dest and matchedSrcPath like so:\n```js\n  rename: function(dest, matchedSrcPath, options) {\n    return path.join(dest, matchedSrcPath);\n  }\n ```\n\n#### options.flatten\nType: `Boolean`\nDefault value: `false`\n\nRemove the path component from all matched src files. The src file path is still joined to the specified dest.\n\n[grunt.file.expandMapping.flatten](http://gruntjs.com/api/grunt.file#grunt.file.expandmapping).\n\n### Include syntax\nCurrently supported: `html`, `haml`, `jade` / `pug`, `scss`, `less` and `ts` (TypeScript).\n\n#### HTML and CSHTML syntax\n`\u003c!-- include: options_go_here_as_json --\u003e`\n\n#### SCSS and LESS syntax\n`// include: options_go_here_as_json`\n\n#### TS syntax\n`/// \u003c!-- include: options_go_here_as_json --\u003e`\n\n#### include.type\nThe type of files that are being included.\nNecessary for choosing the template for output. See `options.templates` for currently supported types.\nSupported types are dependend on the file type you include them from.\n\n#### include.bower\n**DEPRECATED**: Use another Grunt plugin which is better suited for this usecase, like [grunt-bower-install](https://github.com/stephenplusplus/grunt-bower-install).\nThis plugin doesn't support the `main` property for example and is mainly used for development purposes to directly include external sources.\n\nInclude files of the specified Bower component. The component should have a `bower.json` meta data with a property called `sources`.\nThis property should contain the files grouped by type, which are passed through the `grunt.file.expand` method.\n\nExample:\n```js\n{\n  \"name\": \"package.name\",\n  ...\n  \"sources\": {\n    \"js\": [\n      \"src/scripts/**/*.js\",\n      \"lib/compiled-templates.js\"\n    ],\n    \"css\": \"src/styles/**/*.css\"\n  }\n}\n```\n\n#### include.files\nInclude the given files. Files are passed through the `grunt.file.expandMapping` method (see `include.rename` and `include.flatten` options).\n\n#### include.basePath\nSet to override the `basePath` set in the options.\n\n#### include.baseUrl\nSet to override the `baseUrl` set in the options.\n\n#### include.ordering\nType: `String`\nDefault value: `undefined`\n\nOrdering method to be used when including files. Currently supported methods are:\n* `undefined` (default) - included files are sorted by their paths alphabetically in ascending order.\n* `'top-down'` - files from the parent directory will be included before files from subdirectories.\n\n#### Overwriting files\n\nTo set the source file as the destination file use an `/include` comment:\n\n```html\n\u003c!-- include: \"type\": \"js\", \"files\": \"js/**/*.js\" --\u003e\n\u003cscript type=\"text/javascript\" src=\"js/_first.js\"\u003e\u003c/script\u003e\n\u003cscript type=\"text/javascript\" src=\"js/lib/dep1.js\"\u003e\u003c/script\u003e\n\u003c!-- /include --\u003e\n```\n\nWhen includeSource is run it will keep the include comments and only update the includes inside it.\n\nThis works the same way for Less/Sass, by using `// /include`.\n\n### Usage Examples\nConfigure your task like this:\n\n```js\ngrunt.initConfig({\n  includeSource: {\n    options: {\n      basePath: 'app',\n      baseUrl: 'public/'\n    },\n    myTarget: {\n      files: {\n        'dist/index.html': 'app/index.tpl.html'\n      }\n    }\n  }\n})\n```\n\nThe file `index.tpl.html` could contain, for example:\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"\u003e\n    \u003ctitle\u003eIndex\u003c/title\u003e\n    \u003cmeta name=\"description\" content=\"\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width\"\u003e\n\n    \u003c!--\n      Automatically include Bower components. Use the \"sources\" object in your bower.json\n      to specify which source files are which.\n    --\u003e\n    \u003c!-- include: \"type\": \"css\", \"bower\": \"yourComponent\" --\u003e\n\n    \u003c!--\n      Include CSS files from a \"tmp\" directory, put there by another task.\n      This shows how to override the default \"basePath\" set in the options.\n    --\u003e\n    \u003c!-- include: \"type\": \"css\", \"basePath\": \"tmp\", \"files\": \"styles/**/*.css\" --\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003c!-- include: \"type\": \"js\", \"bower\": \"yourComponent\" --\u003e\n    \u003c!-- include: \"type\": \"js\", \"files\": \"scripts/**/*.js\" --\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\nAnd the resulting file `index.html` will look something like:\n```html\n\u003c!doctype html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003cmeta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\"\u003e\n    \u003ctitle\u003eIndex\u003c/title\u003e\n    \u003cmeta name=\"description\" content=\"\"\u003e\n    \u003cmeta name=\"viewport\" content=\"width=device-width\"\u003e\n\n    \u003c!--\n      Automatically include Bower components. Use the \"sources\" object in your bower.json\n      to specify which source files are which.\n    --\u003e\n    \u003c!-- include: \"type\": \"css\", \"bower\": \"yourComponent\" --\u003e\n\n    \u003c!--\n      Include CSS files from a \"tmp\" directory, put there by another task.\n      This shows how to override the default \"basePath\" set in the options.\n    --\u003e\n    \u003clink href=\"public/styles/main.css\" rel=\"stylesheet\" type=\"text/css\" /\u003e\n    \u003clink href=\"public/styles/anotherFile.css\" rel=\"stylesheet\" type=\"text/css\" /\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cscript src=\"public/bower_components/yourComponent/main.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"public/scripts/app.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"public/scripts/anotherFile.js\"\u003e\u003c/script\u003e\n    \u003cscript src=\"public/scripts/controllers/evenMore.js\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Contributing\nIn lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).\n\n## Release History\nSee [CHANGELOG.md](https://github.com/jwvdiermen/grunt-include-source/blob/master/CHANGELOG.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwvdiermen%2Fgrunt-include-source","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjwvdiermen%2Fgrunt-include-source","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjwvdiermen%2Fgrunt-include-source/lists"}