{"id":15020117,"url":"https://github.com/coco-platform/webpack-plugin-inject-external","last_synced_at":"2026-01-21T18:01:48.605Z","repository":{"id":24583063,"uuid":"101971195","full_name":"coco-platform/webpack-plugin-inject-external","owner":"coco-platform","description":"Inject externals CDN resource automatic, cooperate with html-webpack-plugin.","archived":false,"fork":false,"pushed_at":"2023-04-25T04:04:24.000Z","size":1339,"stargazers_count":0,"open_issues_count":12,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T21:18:32.515Z","etag":null,"topics":["webpack","webpack-plugin","webpack2"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/coco-platform.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-31T07:13:56.000Z","updated_at":"2021-01-30T08:31:38.000Z","dependencies_parsed_at":"2024-09-22T16:01:41.036Z","dependency_job_id":null,"html_url":"https://github.com/coco-platform/webpack-plugin-inject-external","commit_stats":{"total_commits":76,"total_committers":6,"mean_commits":"12.666666666666666","dds":0.5394736842105263,"last_synced_commit":"586ce83aa200af26da7e63fc5d7fc0f4c595e54e"},"previous_names":["bornkiller/webpack-plugin-inject-external"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coco-platform%2Fwebpack-plugin-inject-external","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coco-platform%2Fwebpack-plugin-inject-external/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coco-platform%2Fwebpack-plugin-inject-external/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/coco-platform%2Fwebpack-plugin-inject-external/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/coco-platform","download_url":"https://codeload.github.com/coco-platform/webpack-plugin-inject-external/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247801170,"owners_count":20998339,"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":["webpack","webpack-plugin","webpack2"],"created_at":"2024-09-24T19:54:36.740Z","updated_at":"2026-01-21T18:01:48.544Z","avatar_url":"https://github.com/coco-platform.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# webpack-plugin-inject-external\n\n![Build Status](https://img.shields.io/travis/coco-platform/webpack-plugin-inject-external/master.svg?style=flat)\n[![Coverage Status](https://coveralls.io/repos/github/coco-platform/webpack-plugin-inject-external/badge.svg?branch=master)](https://coveralls.io/github/coco-platform/webpack-plugin-inject-external?branch=master) [![Greenkeeper badge](https://badges.greenkeeper.io/coco-platform/webpack-plugin-inject-external.svg)](https://greenkeeper.io/)\n![Package Dependency](https://david-dm.org/coco-platform/webpack-plugin-inject-external.svg?style=flat)\n![Package DevDependency](https://david-dm.org/coco-platform/webpack-plugin-inject-external/dev-status.svg?style=flat)\n\n## Usage\n\n```shell\n# npm\nnpm install @coco-platform/webpack-plugin-inject-external --only=dev;\n# yarn\nyarn add @coco-platform/webpack-plugin-inject-external --dev;\n```\n\n## Options\n\n```javascript\n/**\n * @typedef {object} Options\n *\n * @property {string} env - development, production or other environment name\n * @property {string} definition - YAML file path, whose contents describe external resources\n */\n```\n\n## Configurations\n\n`webpack-plugin-inject-external` use `yaml` config file, single external module define like below:\n\n```typescript\ninterface CompoundLinkage {\n  url: string;\n  integrity: string; // required property within compound mode\n}\n\ntype Linkage = string | string[] | CompoundLinkage | Array\u003cCompoundLinkage\u003e;\n\n// single external module\ntype Module = {\n  name: string;\n  linkage: Linkage;\n};\n```\n\nwhen external module reference the same resource within different environment:\n\n```yaml\nlibrary:\n  - name: 'web-animations-js'\n    linkage: 'https://unpkg.com/web-animations-js@2.3.1/web-animations.min.js'\n```\n\nwhen external module reference different resource within different environment:\n\n```yaml\nenvironment:\n  development:\n    - name: 'react'\n      linkage: 'https://cdn.bootcss.com/react/16.3.2/umd/react.development.js'\n    - name: 'moment'\n      linkage:\n        - 'https://cdn.bootcss.com/moment.js/2.22.1/moment.js'\n        - 'https://cdn.bootcss.com/moment.js/2.22.1/locale/zh-cn.js'\n  production:\n    - name: 'react'\n      linkage:\n        url: 'https://cdn.bootcss.com/react/16.3.2/umd/react.production.min.js'\n        integrity: 'sha384-xH6t0qiGSnjsUirN+xJjNhsfepiFFyK/wHMjrqPu6OoxN8uDO454QqZx3Wcos7en'\n```\n\n## Usage\n\nThen config the webpack:\n\n```javascript\nconst configuration = {\n  entry: path.resolve(__dirname, '__fixture__', 'index.js'),\n  output: {\n    path: path.resolve(process.cwd(), 'dist'),\n    filename: '[name].js',\n    publicPath: '/',\n  },\n  externals: {\n    moment: 'moment',\n  },\n  plugins: [\n    new HtmlWebpackPlugin({\n      template: path.resolve(__dirname, '__fixture__', 'index.html'),\n      inject: 'body',\n    }),\n    new InjectExternalPlugin({\n      env: 'production',\n      definition: path.resolve(\n        __dirname,\n        '__fixture__',\n        'bootcdn.externals.yml'\n      ),\n    }),\n  ],\n};\n```\n\nFinally output:\n\n```html\n\u003chtml lang=\"en\"\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"UTF-8\" /\u003e\n    \u003ctitle\u003eWebpack Plugin\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cscript\n      type=\"text/javascript\"\n      src=\"https://cdn.bootcss.com/moment.js/2.22.1/moment.min.js\"\n      crossorigin=\"anonymous\"\n      integrity=\"sha384-fYxN7HsDOBRo1wT/NSZ0LkoNlcXvpDpFy6WzB42LxuKAX7sBwgo7vuins+E1HCaw\"\n    \u003e\u003c/script\n    \u003e\u003cscript\n      type=\"text/javascript\"\n      src=\"https://cdn.bootcss.com/moment.js/2.22.1/locale/zh-cn.js\"\n      crossorigin=\"anonymous\"\n      integrity=\"sha384-XjUTsP+pYBX4Kwg40gPvhWcRGKZh9gUpDForgg5bwsnyNU+VabKhRX6XkyM6fLk4\"\n    \u003e\u003c/script\n    \u003e\u003cscript type=\"text/javascript\" src=\"/main.js\"\u003e\u003c/script\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoco-platform%2Fwebpack-plugin-inject-external","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcoco-platform%2Fwebpack-plugin-inject-external","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcoco-platform%2Fwebpack-plugin-inject-external/lists"}