npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

xml-webpack-plugin

v1.3.0

Published

Use templates to generate XML files in your webpack project

Downloads

27,732

Readme

Build Status

XML Webpack Plugin

This is a webpack plugin that allows you to generate XML files based on ejs templates.

Maintainer: René van Mil

Requirements

Webpack 4.x or 5.x

Installation

Install the plugin with npm:

$ npm install xml-webpack-plugin --save-dev

or with yarn:

$ yarn add -D xml-webpack-plugin

Usage

Example - browserconfig.xml

This example will generate a browserconfig.xml file inside the output path of your webpack bundle.

browserconfig.ejs

<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
    <msapplication>
        <tile>
            <square70x70logo src="<%= square70x70logo %>"/>
            <square150x150logo src="<%= square150x150logo %>"/>
            <wide310x150logo src="<%= wide310x150logo %>"/>
            <square310x310logo src="<%= square310x310logo %>"/>
            <TileColor><%= tileColor %></TileColor>
        </tile>
    </msapplication>
</browserconfig>

webpack.config.js

const XMLWebpackPlugin = require('xml-webpack-plugin')

const xmlFiles = [
    {
        template: path.join(__dirname, 'browserconfig.ejs'),
        filename: 'browserconfig.xml',
        data: {
            square70x70logo: 'images/icon70.png',
            square150x150logo: 'images/icon150.png',
            wide310x150logo: 'images/icon310x150.png',
            square310x310logo: 'images/icon310.png',
            tileColor: '#ffffff'
        }
    }
]

const webpackConfig = {
    plugins: [
        new XMLWebpackPlugin({
            files: xmlFiles,
			options: {
				delimiter: '%',
				openDelimiter: '<',
				closeDelimiter: '>'
			}
        })
    ]
}

Example - Cordova config.xml

This example will generate a config.xml file inside the context path of your webpack project, which means the file will not be part of your webpack bundle but becomes part of your project folder instead. This is especially useful for e.g. generating a Cordova configuration file, which will be used by the Cordova compilation step after you generate your webpack bundle.

cordovaConfig.ejs

<?xml version="1.0" encoding="utf-8"?>
<widget id="com.example.hello" version="<%= version %>" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name><%= name %></name>
    <description>
        <%= description %>
    </description>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <%_ allowIntents.forEach(function(allowIntent) { _%>
    <allow-intent href="<%= allowIntent %>" />
    <%_ }) _%>
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

webpack.config.js

const pkg = require('./package.json')
const XMLWebpackPlugin = require('xml-webpack-plugin')

const xmlFiles = [
    {
        template: path.join(__dirname, 'cordovaConfig.ejs'),
        filename: 'config.xml',
        writeToContext: true,
        data: {
            version: pkg.version,
            name: 'myApp',
            description: 'This is the description of my app',
            allowIntents: [
                'http://*/*',
                'https://*/*',
                'tel:*',
                'sms:*',
                'mailto:*',
                'geo:*'
            ]
        }
    }
]

const webpackConfig = {
    plugins: [
        new XMLWebpackPlugin({
            files: xmlFiles,
			options: {
				delimiter: '%',
				openDelimiter: '<',
				closeDelimiter: '>'
			}
        })
    ]
}

XML File Options

The files array passed to the plugin must contain objects with these values:

  • template: required - Path to the ejs template file which will be used to generate the XML output file.
  • filename: required - The file to write the XML to.
  • path: optional - The relative folder path to write the file to. When writeToContext is set to true you have to make sure this folder already exists inside your project folder.
  • writeToContext: optional - When set to true the file will not be written to the webpack bundle output, but to the webpack project folder instead.
  • data: optional - An object containing the data which will be passed to the ejs compiler.

The options object passed to the plugin is optional. It can contain any of the ejs library options.

Contribution

You're free to contribute to this project by submitting issues and/or pull requests.

License

This project is licensed under MIT.