{"id":16485821,"url":"https://github.com/creeperyang/html-webpack-select-assets-plugin","last_synced_at":"2025-07-04T06:06:32.605Z","repository":{"id":57267872,"uuid":"342230992","full_name":"creeperyang/html-webpack-select-assets-plugin","owner":"creeperyang","description":"Select certain output files to the html file. Works with newer html-webpack-plugin versions.","archived":false,"fork":false,"pushed_at":"2021-02-28T12:40:30.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T00:12:09.480Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creeperyang.png","metadata":{"files":{"readme":"README.md","changelog":null,"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-02-25T12:03:32.000Z","updated_at":"2021-02-28T15:59:45.000Z","dependencies_parsed_at":"2022-09-02T03:40:12.438Z","dependency_job_id":null,"html_url":"https://github.com/creeperyang/html-webpack-select-assets-plugin","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/creeperyang/html-webpack-select-assets-plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-webpack-select-assets-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-webpack-select-assets-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-webpack-select-assets-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-webpack-select-assets-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creeperyang","download_url":"https://codeload.github.com/creeperyang/html-webpack-select-assets-plugin/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creeperyang%2Fhtml-webpack-select-assets-plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263457183,"owners_count":23469289,"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-10-11T13:27:23.521Z","updated_at":"2025-07-04T06:06:32.576Z","avatar_url":"https://github.com/creeperyang.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# html-webpack-select-assets-plugin\nSelect certain output files to the html file. Works with newer html-webpack-plugin versions.\n\n[![Build Status](https://travis-ci.com/creeperyang/html-webpack-select-assets-plugin.svg?branch=main)](https://travis-ci.com/creeperyang/html-webpack-select-assets-plugin)\n\n[![NPM](https://nodei.co/npm/html-webpack-select-assets-plugin.png)](https://nodei.co/npm/html-webpack-select-assets-plugin/)\n\n\u003e Only for webpack@5 and html-webpack-plugin@5 or higher.\n## Usage\n\n1. Install via `npm i -D html-webpack-select-assets-plugin`.\n1. Add to your webpack config **AFTER** HtmlWebpackPlugin.\n\n```js\nconst HtmlWebpackSelectAssetsPlugin = require('html-webpack-select-assets-plugin');\n// OR\nimport HtmlWebpackSelectAssetsPlugin from 'html-webpack-select-assets-plugin';\n\n// And for webpack config\n{\n    entry: {\n        app: join(__dirname, './src/entry.js'),\n        other: join(__dirname, './src/other.js'),\n    },\n    // ...\n    plugins: [\n        new HtmlWebpackPlugin({\n            filename: (entry) =\u003e `${entry}.html`,\n            template: join(__dirname, './src/index.html'),\n        }),\n        new HtmlWebpackSelectAssetsPlugin({\n            selector: 'smart',\n        }),\n    ]\n}\n```\n\nThe plugin takes a configuration argument with a key called `selector`. It will help you to select assets to the specified output html.\n\nThe typical or **most powerful usage case** is when you deal with **multiple** html pages:\n\n- You have multiple `entry` for webpack entry config;\n- Only one HtmlWebpackPlugin instance and config with `filename: (entry) =\u003e entry + '.html'` to generate multiple html files (one-to-one correspond to each entry point).\n\nThe problem is that HtmlWebpackPlugin will inject all (entries') assets files to each html file. What if you only want the corresponding entry's assets? \n\nThis is why `html-webpack-select-assets-plugin` here -- select assets corresponding to the entry.\n\n## Powerful `selector` option\n\n- **`\"smart\"`**: only select assets corresponding to each entry automatically. This means if you want to generate `app.html` for `entry:app.js`, only `app.js` and assets imported by `app.js` will be injected.\n\n- **`function selector(asset:HtmlTagObject, context:SelectorContext, type:AssetType):boolean`**: you can write your custom selector function to choose assets flexibly. \n\n    - `HtmlTagObject`: `{attributes,meta,tagName}`, the type is defined by `html-webpack-plugin` and represents the asset.\n    - `SelectorContext`: `{entry:string, outputName:string, entryFiles:string[]}`, the context info for the asset. `entry` means entry name, `outputName` is current generated html file's name, and `entryFiles` means all assets associated with the `entry`.\n    - `AssetType`: enum `\"script\"|\"style\"|\"meta\"`, means the type of the asset.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreeperyang%2Fhtml-webpack-select-assets-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreeperyang%2Fhtml-webpack-select-assets-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreeperyang%2Fhtml-webpack-select-assets-plugin/lists"}