Create File Webpack Plugin
raw JSON → 1.0.2 verified Sat Apr 25 auth: no javascript
A simple Webpack plugin that creates a file with specified content at the end of the build process. Version 1.0.2 is the current stable release, with no active maintenance or updates since 2019. It differentiates from similar plugins (e.g., `write-file-webpack-plugin`) by its minimalism: only three options (`path`, `fileName`, `content`). Works with Webpack 4 and earlier; compatibility with Webpack 5 is untested and likely requires adjustments due to hook changes.
Common errors
error Error: 'options.path' must be a string ↓
cause path option missing or not a string
fix
Ensure path is a string, e.g., new CreateFileWebpack({ path: './dist', ... })
error TypeError: Cannot read property 'afterCompile' of undefined ↓
cause Incompatible with Webpack 5 (hook changed).
fix
Use Webpack 4 or patch the plugin.
error Error: Cannot find module 'create-file-webpack' ↓
cause Package not installed or require path incorrect.
fix
Run 'npm install create-file-webpack --save-dev' and verify node_modules.
Warnings
breaking Webpack 5 may not work due to hook changes. ↓
fix Use an alternative plugin or check for updates on GitHub. Consider using 'write-file-webpack-plugin' or custom code.
gotcha Plugin does not create directories recursively; path must exist. ↓
fix Ensure the output directory exists or use 'mkdirp' before running Webpack.
gotcha Content is always a string; no support for Buffer or streams. ↓
fix Convert non-string content to string before passing.
deprecated Plugin has not been updated since 2019; newer Webpack versions may break. ↓
fix Consider migrating to a maintained alternative.
Install
npm install create-file-webpack yarn add create-file-webpack pnpm add create-file-webpack Imports
- CreateFileWebpack wrong
import CreateFileWebpack from 'create-file-webpack'correctconst CreateFileWebpack = require('create-file-webpack') - default wrong
const { default: CreateFileWebpack } = require('create-file-webpack')correctconst CreateFileWebpack = require('create-file-webpack') - CreateFileWebpack (TypeScript) wrong
import CreateFileWebpack from 'create-file-webpack'correctimport CreateFileWebpack = require('create-file-webpack')
Quickstart
const CreateFileWebpack = require('create-file-webpack');
// webpack.config.js
module.exports = {
entry: './src/index.js',
output: {
path: __dirname + '/dist',
filename: 'bundle.js'
},
plugins: [
new CreateFileWebpack({
path: './dist',
fileName: 'version.txt',
content: '1.0.0'
})
]
};