XML Webpack Plugin
raw JSON → 1.3.0 verified Sat Apr 25 auth: no javascript maintenance
A webpack plugin (v1.3.0) that generates XML files using EJS templates. Supports Webpack 4.x and 5.x. Key differentiators: it integrates seamlessly into the webpack build pipeline, allows writing XML to the output path or project context path, and uses the popular EJS templating engine. The project is in maintenance mode with no recent updates.
Common errors
error Error: Cannot find module 'ejs' ↓
cause ejs is not installed as a dependency
fix
npm install ejs --save-dev
error TypeError: files is not iterable ↓
cause The 'files' property is missing or not an array
fix
Ensure the plugin options include: { files: [...] }
error TypeError: Cannot read property 'readFileSync' of undefined ↓
cause The template file path does not exist or is not absolute
fix
Use an absolute path or ensure the file exists at the given relative path.
Warnings
deprecated Package has not been updated in years; may be deprecated for use with newer webpack versions beyond 5.x. ↓
fix Consider using html-webpack-plugin with ejs-loader for XML generation.
gotcha Plugin requires a 'files' array; passing an empty array or missing 'files' will cause the plugin to silently do nothing. ↓
fix Always provide at least one file object in the 'files' array.
gotcha Template paths must be absolute; relative paths may not resolve correctly. ↓
fix Use path.join(__dirname, 'template.ejs') to generate absolute paths.
Install
npm install xml-webpack-plugin yarn add xml-webpack-plugin pnpm add xml-webpack-plugin Imports
- XMLWebpackPlugin wrong
import XMLWebpackPlugin from 'xml-webpack-plugin'correctconst XMLWebpackPlugin = require('xml-webpack-plugin') - XMLWebpackPlugin wrong
new XMLWebpackPlugin()correctconst XMLWebpackPlugin = require('xml-webpack-plugin'); new XMLWebpackPlugin(options) - files array wrong
files: [ 'path/to/template.ejs' ]correctfiles: [ { template: 'path/to/template.ejs', filename: 'output.xml' } ]
Quickstart
const path = require('path');
const XMLWebpackPlugin = require('xml-webpack-plugin');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
plugins: [
new XMLWebpackPlugin({
files: [
{
template: path.join(__dirname, 'template.ejs'),
filename: 'output.xml',
data: { message: 'Hello World' },
}
],
options: {
delimiter: '%',
openDelimiter: '<',
closeDelimiter: '>',
},
}),
],
};