{"id":15003645,"url":"https://github.com/halo-lab/eleventy-plugin-scripts","last_synced_at":"2025-10-03T14:31:28.345Z","repository":{"id":57222342,"uuid":"355919319","full_name":"Halo-Lab/eleventy-plugin-scripts","owner":"Halo-Lab","description":"Eleventy plugin to process scripts from HTML.","archived":true,"fork":false,"pushed_at":"2022-01-18T07:39:08.000Z","size":166,"stargazers_count":8,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-18T22:26:08.807Z","etag":null,"topics":["bundling","eleventy","esbuild","javascript","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Halo-Lab.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-08T13:31:23.000Z","updated_at":"2024-07-02T19:27:38.000Z","dependencies_parsed_at":"2022-09-07T16:20:55.639Z","dependency_job_id":null,"html_url":"https://github.com/Halo-Lab/eleventy-plugin-scripts","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Halo-Lab%2Feleventy-plugin-scripts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Halo-Lab%2Feleventy-plugin-scripts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Halo-Lab%2Feleventy-plugin-scripts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Halo-Lab%2Feleventy-plugin-scripts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Halo-Lab","download_url":"https://codeload.github.com/Halo-Lab/eleventy-plugin-scripts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":235146460,"owners_count":18943262,"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":["bundling","eleventy","esbuild","javascript","typescript"],"created_at":"2024-09-24T18:59:41.480Z","updated_at":"2025-10-03T14:31:28.028Z","avatar_url":"https://github.com/Halo-Lab.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# eleventy-plugin-scripts 📜\n\n**⚠️ This code moves to [the new location](https://github.com/Halo-Lab/eleventy-packages). Please, refer there to get a new development status.**\n\n[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)\n\nBundles scripts of your site 💪\n\n## Intention\n\nIt is not convenient to use a third-party tools like [`gulp`](https://gulpjs.com/), [`webpack`](https://webpack.js.org/) or whatever you know for processing scripts. Yeah 🤨... But why not to intergate this process with [`Eleventy`](https://www.11ty.dev/)? Sounds cool, right 😋!\n\n## Get started\n\nWhat this plugin can do:\n\n1. Fast bundling your JavaScript or TypeScript files. Thank you [`esbuild`](https://esbuild.github.io)!\n2. Setting correct relative paths between HTML and bundled JavaScript.\n\n### Installation\n\nAt first do:\n\n```sh\nnpm i -D eleventy-plugin-scripts\n```\n\nand then you can include it into `.eleventy.js`:\n\n```js\nconst { scripts } = require('eleventy-plugin-scripts');\n\nmodule.exports = (eleventyConfig) =\u003e {\n  eleventyConfig.addPlugin(scripts, {\n    /* Optional options. */\n  });\n};\n```\n\n### Options\n\nPlugin can accept the following options:\n\n```ts\ninterface ScriptsPluginOptions {\n  /**\n   * Path to directory with all scripts\n   * Should be relative to _current working directory_.\n   */\n  inputDirectory?: string;\n  /**\n   * Directory inside _output_ folder to be used as\n   * warehouse for all compiled scripts. Will be\n   * prepended to public script urls in HTML.\n   */\n  publicDirectory?: string;\n  /**\n   * Options that can be passed to [`esbuild`](https://esbuild.github.io).\n   */\n  esbuildOptions?: BuildOptions;\n  /**\n   * Indicates whether should Eleventy watch on files\n   * under _inputDirectory_ or not.\n   */\n  addWatchTarget?: boolean;\n}\n```\n\n### Explanation\n\n#### inputDirectory\n\nPlugin extracts URLs to script files from HTML. Therefore your templates should have links to **source** script files.\n\nFor example:\n\n```html\n\u003c!-- Note that we wrote `main.ts` 👇 --\u003e\n\u003cscript type=\"module\" src=\"main.ts\"\u003e\u003c/script\u003e\n```\n\n\u003e Plugin recognizes followed extensions: `js` and `ts`. In future may be added much more if you will need it 🤓\n\nAfter URL extraction plugin will search for these files inside _inputDirectory_ from _options_. So given above example:\n\n```js\n// .eleventy.js\nmodule.exports = (eleventyConfig) =\u003e {\n  eleventyConfig.addPlugin(scripts, {\n    // This is a default value\n    inputDirectory: 'src/scripts',\n  });\n};\n```\n\nPlugin will assume that path of script file is `src/scripts/main.ts` 🎉 And after all procedures will put compiled file to `_site/main.js` and URL in HTML will be changed to:\n\n```html\n\u003c!-- If HTML file is in the same directory if main.js --\u003e\n\u003cscript type=\"module\" src=\"main.js\"\u003e\u003c/script\u003e\n```\n\n\u003e `_site` is used just for example. Actually [name of the directory will be up to you](https://www.11ty.dev/docs/config/#output-directory) - plugin will know about it.\n\n\u003e If HTML file is in other directory, then referenced script file, plugin will build relative path to it. For example, if output of HTML is `_site/pages/about/index.html` and script's public path is `main.js`(in root of `_site`), then plugin formats public path to `../../main.js`. So you aren't needed to fix URLs to your assets 🤘!\n\n#### publicDirectory\n\nIf you want to customize output path of compiled script inside _output_ directory, then you can provide _publicDirectory_ option.\n\n```js\n// .eleventy.js\nmodule.exports = (eleventyConfig) =\u003e {\n  eleventyConfig.addPlugin(scripts, {\n    inputDirectory: 'src/scripts',\n    publicDirectory: 'scripts',\n  });\n};\n```\n\nGiven above example, script file will be placed into `_site/scripts` directory and it's public path will be `scripts/main.js`.\n\nPretty convenient, yes? 🙂\n\n### addWatchTarget\n\nBy default Eleventy will watch for changes inside _inputDirectory_. You have an opportunity to disable it:\n\n```js\n// .eleventy.js\nmodule.exports = (eleventyConfig) =\u003e {\n  eleventyConfig.addPlugin(scripts, {\n    // Now Eleventy will not trigger rebuild process\n    // if any script changes.\n    addWatchTarget: false,\n  });\n};\n```\n\n### esbuildOptions\n\nInternally for bundling scripts is responsible [`esbuild`](https://esbuild.github.io). It bundles each script with all dependencies, that you will reference from templates, into one [ES2018]-compliant file.\n\nYou customize its behavior by providing [build options](https://esbuild.github.io/api/#simple-options).\n\n```js\n// .eleventy.js\nmodule.exports = (eleventyConfig) =\u003e {\n  eleventyConfig.addPlugin(scripts, {\n    esbuildOptions: {\n      /* Some useful options. */\n    },\n  });\n};\n```\n\n\u003e Avoid changing `entryPoints` and `outfile` properties, because in HTML may be passed wrong script URL.\n\n## Word from author\n\nHave fun! ✌️\n\n\u003ca href=\"https://www.halo-lab.com/?utm_source=github\"\u003e\n  \u003cimg src=\"https://dgestran.sirv.com/Images/supported-by-halolab.png\" alt=\"Supported by Halo lab\" height=\"60\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalo-lab%2Feleventy-plugin-scripts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhalo-lab%2Feleventy-plugin-scripts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhalo-lab%2Feleventy-plugin-scripts/lists"}