LicensePluginJson
is a Vite-compatible plugin that uses rollup-plugin-license to generate a JSON file containing detailed information about third-party licenses in your project.
To use this plugin, install it via npm:
npm install @darcas/rollup-plugin-license-json
Or, if you're using yarn:
yarn add @darcas/rollup-plugin-license-json
In your vite.config.mts
just add:
import LicensePluginJson from '@darcas/rollup-plugin-license-json';
import { defineConfig } from 'vite'
export default defineConfig({
//...
plugins: [
//...
LicensePluginJson(join(__dirname, 'dist', 'licenses.json'), {
debug: true,
thirdParty: {
includePrivate: true,
multipleVersions: true,
}
}),
//...
],
//...
});
LicensePluginJson
accepts 2 parameters:
file
(string, required): The path where the JSON file will be generated.options
(object, optional): See therollup-plugin-license
plugin
You can't override the
thirdParty.output
option.
The plugin generates a JSON file with the following structure for each dependency:
type LicensePluginJsonRecord = {
readonly author: {
readonly name: string
readonly email: string | null
readonly url: string | null
} | null
readonly description: string
readonly homepage: string
readonly license: string
readonly licenseText: string
readonly name: string
readonly version: string
}
licenseText
: If the license text is empty or unavailable, it will be omitted.- Formatting: HTML tags are removed, and newlines are replaced with
<br>
tags to preserve readability.
Assuming your project contains the following dependencies:
axios
lodash
The generated JSON file might look like this:
[
{
"name": "axios",
"version": "0.21.4",
"author": {
"name": "Matt Zabriskie",
"email": "[email protected]"
},
"description": "Promise based HTTP client for the browser and node.js",
"homepage": "https://axios-http.com/",
"license": "MIT",
"licenseText": "Permission is hereby granted, free of charge, to any person..."
},
{
"name": "lodash",
"version": "4.17.21",
"author": {
"name": "John-David Dalton",
"email": "[email protected]"
},
"description": "A modern JavaScript utility library delivering modularity, performance, and extras.",
"homepage": "https://lodash.com/",
"license": "MIT",
"licenseText": "Permission is hereby granted, free of charge, to any person..."
}
]
<script lang="ts" setup>
import { type LicensePluginJsonRecord } from '@darcas/rollup-plugin-license-json';
import axios from "axios";
import orderBy from 'lodash/orderBy';
const licenses = ref<LicensePluginJsonRecord[]>([]);
onMounted(async () => {
const response = await axios.get('/licenses.json', {
headers: {
Accept: 'application/json',
},
});
if (response.status === 200) {
licenses.value = orderBy(response.data, ['name'], ['asc']);
}
});
</script>
LicensePluginJson
is built on top of rollup-plugin-license. It uses its core functionality to extract and format license information for third-party dependencies. Ensure that your project setup supports Rollup-compatible plugins, as Vite uses Rollup under the hood.
If you'd like to contribute to the project, feel free to fork it and create a pull request. Please ensure that your changes are well-tested and properly documented.
This project is licensed under the MIT License. See the LICENSE file for details.
Made with ❤️ by Dario Casertano (DarCas).