{"id":14976405,"url":"https://github.com/gyumeijie/write-file-webpack","last_synced_at":"2026-02-06T09:40:09.507Z","repository":{"id":57151028,"uuid":"153395732","full_name":"Gyumeijie/write-file-webpack","owner":"Gyumeijie","description":"A simple webpack(v3) plugin for writing data to file.","archived":false,"fork":false,"pushed_at":"2018-10-17T04:54:43.000Z","size":4,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-04-02T01:14:31.279Z","etag":null,"topics":["webpack-plugin","webpack3","writefile"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/write-file-webpack","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/Gyumeijie.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}},"created_at":"2018-10-17T04:32:51.000Z","updated_at":"2023-11-20T20:15:13.000Z","dependencies_parsed_at":"2022-08-27T06:11:03.400Z","dependency_job_id":null,"html_url":"https://github.com/Gyumeijie/write-file-webpack","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Gyumeijie/write-file-webpack","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyumeijie%2Fwrite-file-webpack","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyumeijie%2Fwrite-file-webpack/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyumeijie%2Fwrite-file-webpack/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyumeijie%2Fwrite-file-webpack/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Gyumeijie","download_url":"https://codeload.github.com/Gyumeijie/write-file-webpack/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Gyumeijie%2Fwrite-file-webpack/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268265819,"owners_count":24222524,"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","status":"online","status_checked_at":"2025-08-01T02:00:08.611Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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-plugin","webpack3","writefile"],"created_at":"2024-09-24T13:53:50.416Z","updated_at":"2026-02-06T09:40:08.501Z","avatar_url":"https://github.com/Gyumeijie.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Write to file plugin for webpack(v3)\n[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)\n\nThis is a simple webpack plugin for writing data to file. And there is a similar [plugin](https://github.com/Gyumeijie/write-to-file-webpack) for webpack v4.\n\n# Features\n1. support creating directory recursively\n2. support data of function type, which allows processing data in complex situation\n3. support native options of underlying writeFileSync\n4. support protection of an exsited file\n\n# Installation\n`npm install --save-dev write-file-webpack`\n\n# Usage\nThe data to be written can be either a simple javascript variable, or a function which returns some data. \n\n```javascript\nconst WriteToFilePlugin = require('write-file-webpack');\n\nmodule.exports = {\n  ...\n  plugins: [\n     new WriteToFilePlugin({ \n        filename: 'path/to/write/file', \n        data: 'console.log(\"write to file\")'\n      })\n  ]\n  ...\n}\n```\n\n```javascript\nconst WriteToFilePlugin = require('write-file-webpack');\n\nmodule.exports = {\n   ...\n   plugins: [\n      new WriteToFilePlugin({ \n         filename: 'path/to/write/file', \n         data: function () {\n            return \"console.log('write to file')\"\n         }\n     })\n   ]\n   ...\n}\n```\n\nIf the `data` is provided as a `function`, we can do more operations than just simply returning the data to be written. For example, if we wanna write to a file parts of an exsited file say `package.json`, and more specifically, removing the `dependencies` and `devDependencies` items, with `write-file-webpack` we can do this:\n\n```javascript\nconst WriteToFilePlugin = require('write-file-webpack');\nconst config = require('./package.json');\n\nmodule.exports = {\n   ...\n   plugins: [\n      new WriteToFilePlugin({ \n         filename: 'path/to/write/package.json', \n         data: function () {\n            return JSON.stringify({\n               ...config,\n               dependencies: undefined,\n               devDependencies: undefined,\n           });\n         }\n     })\n   ]\n   ...\n}\n```\nOf course, if we want to copy the whole content of a existed file, there is webpack plugin called `copy-webpack-plugin`.\n\n# Support\n`node \u003e= 6` and `webpack v3`\n\n# Options\n- filename (**required**)\n- data (**required**)\n- override          \n`\u003cboolean\u003e Default: true`, if set to false, no data will be written to an exsited file \n- encoding     \n`\u003cstring\u003e | \u003cnull\u003e Default: 'utf8'`\n- mode       \n`\u003cinteger\u003e Default: 0o666`\n- flag        \n`\u003cstring\u003e Default: 'w'`\n\nFor more information about `encoding`, `mode`, and `flag` please refer to [node writeFile](https://nodejs.org/docs/latest-v9.x/api/fs.html#fs_fs_writefilesync_file_data_options).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyumeijie%2Fwrite-file-webpack","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgyumeijie%2Fwrite-file-webpack","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgyumeijie%2Fwrite-file-webpack/lists"}