{"id":19670043,"url":"https://github.com/levp/wrapper-webpack-plugin","last_synced_at":"2025-04-05T16:09:57.715Z","repository":{"id":3581495,"uuid":"50218147","full_name":"levp/wrapper-webpack-plugin","owner":"levp","description":"A webpack plugin that wraps output files (chunks) with custom text or code.","archived":false,"fork":false,"pushed_at":"2023-08-09T01:16:01.000Z","size":32,"stargazers_count":92,"open_issues_count":9,"forks_count":35,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-01-12T09:51:54.863Z","etag":null,"topics":["webpack","webpack-plugin"],"latest_commit_sha":null,"homepage":"","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/levp.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-01-23T01:39:43.000Z","updated_at":"2024-12-11T13:59:44.000Z","dependencies_parsed_at":"2024-06-18T13:02:52.290Z","dependency_job_id":"1dc3642c-4445-43a4-bc68-0f1db6804d82","html_url":"https://github.com/levp/wrapper-webpack-plugin","commit_stats":{"total_commits":71,"total_committers":6,"mean_commits":"11.833333333333334","dds":0.323943661971831,"last_synced_commit":"5f692f1fde125313a5b21a646031a259f028fae2"},"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levp%2Fwrapper-webpack-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levp%2Fwrapper-webpack-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levp%2Fwrapper-webpack-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/levp%2Fwrapper-webpack-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/levp","download_url":"https://codeload.github.com/levp/wrapper-webpack-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247361693,"owners_count":20926643,"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"],"created_at":"2024-11-11T17:03:48.936Z","updated_at":"2025-04-05T16:09:57.698Z","avatar_url":"https://github.com/levp.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# A webpack plugin that wraps output files (chunks) with custom text or code.\n\n## Installation\n\nInstall locally using npm:  \n`npm i -D wrapper-webpack-plugin`\n\n#### Webpack compatibility\n\nVersion 2 of this plugin only works with webpack \u003e=4.\\\nFor webpack \u003c4 use [version 1](https://github.com/levp/wrapper-webpack-plugin/tree/v1) of the plugin with `npm i -D wrapper-webpack-plugin@1` \n\n## Usage\n\nThe `WrapperPlugin` class has a single parameter, an object with a `header` and/or `footer` properties. Header text will\nbe *prepended* to the output file, footer text will be *appended*. These can be either a string or a function. A string\nwill simply be a appended/prepended to the file output. A function is expected to return a string, and will receive the\nname of the output file as an argument.\n\nAn optional `test` property (a string or a `RegExp` object) can control which output files are affected; otherwise all output files will be wrapped.\n\n*New in 2.1:*  \nThe optional `afterOptimizations` property can be used to avoid having the added text affected by the optimization stage, e.g. if you don't want it to be minified. \n\n## API\n\n```\nfunction WrapperPlugin({\n    test: string | RegExp,\n    header: string | function,\n    footer: string | function,\n    afterOptimizations: bool // default: false\n})\n```\n\n## Example configuration #1\n\nWraps bundle files with '.js' extension in a self invoking function and enables strict mode:\n\n```javascript\nconst WrapperPlugin = require('wrapper-webpack-plugin');\n\nmodule.exports = {\n  // other webpack config here\n  \n  plugins: [\n    // strict mode for the whole bundle\n    new WrapperPlugin({\n      test: /\\.js$/, // only wrap output of bundle files with '.js' extension \n      header: '(function () { \"use strict\";\\n',\n      footer: '\\n})();'\n    })\n  ]\n};\n```\n\n## Example configuration #2\n\nPrepends bundles with a doc comment:\n\n```javascript\nconst WrapperPlugin = require('wrapper-webpack-plugin');\n\nmodule.exports = {\n  // other webpack config here\n  \n  plugins: [\n    new WrapperPlugin({\n      header: function (fileName) {\n        return '/*! file: ' + fileName + ', created by dev123 */\\n';\n      }\n    })\n  ]\n};\n```\n\n## Example configuration #3\n\nAccessing file name, build hash, and chunk hash at runtime.\n\n```javascript\nconst WrapperPlugin = require('wrapper-webpack-plugin');\n\nmodule.exports = {\n  // other webpack config here\n\t\n  output: {\n    filename: '[name].[chunkhash].js'\n  },\n  plugins: [\n    new WrapperPlugin({\n      header: `(function (FILE_NAME, BUILD_HASH, CHUNK_HASH) {`,\n      footer(fileName, args) {\n        return `})('${fileName}', '${args.hash}', '${args.chunkhash}');`;\n        // note: args.hash and args.chunkhash correspond to the [hash] and [chunkhash] \n        // placeholders you can specify in the output.filename option.\n      }\n    })\n  ]\n};\n```\n\n## Example configuration #4\n\nKeeping header in a separate file:\n\nfile: `header.js`\n```javascript\n/*!\n * my awesome app!\n */\n```\n\nfile: `webpack.config`\n```javascript\nconst fs = require('fs');\n WrapperPlugin = require('wrapper-webpack-plugin');\n\nconst headerDoc = fs.readFileSync('./header.js', 'utf8');\n\nmodule.exports = {\n  // other webpack config here\n\n  plugins: [\n    new WrapperPlugin({\n      header: headerDoc\n    })\n  ]\n};\n```\n\n## Example configuration #5\n\nA slightly more complex example using `lodash` templates:\n\n```javascript\nconst WrapperPlugin = require('wrapper-webpack-plugin');\nconst template = require('lodash.template');\nconst pkg = require('./package.json');\n\nconst tpl = '/*! \u003c%= name %\u003e v\u003c%= version %\u003e | \u003c%= author %\u003e */\\n';\n\nmodule.exports = {\n  // other webpack config here\n\n  plugins: [\n    new WrapperPlugin({\n      header: template(tpl)(pkg)\n    })\n  ]\n};\n```\n\n## Compatibility with other plugins\n\nThis plugin should play nicely with most other plugins.\nE.g. adding the `webpack.optimize.UglifyJsPlugin` plugin to the plugins array *after* the `WrapperPlugin` will result in\nthe wrapper text also being minified.\n\n## License\n\n[ISC](https://opensource.org/licenses/ISC)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevp%2Fwrapper-webpack-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flevp%2Fwrapper-webpack-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flevp%2Fwrapper-webpack-plugin/lists"}