aboutsummaryrefslogtreecommitdiff
path: root/webpack.config.js
diff options
context:
space:
mode:
authorsilverwind2020-06-12 13:26:37 +0200
committerGitHub2020-06-12 14:26:37 +0300
commitbc4f7ba69b01c6f10f6ea26325bf61485adaa0ff (patch)
tree3b7a6dafcc034b2f9605b20673cad4d82d25a844 /webpack.config.js
parent2b573f49cf42cf157b89db3acc1c1dfa0d33cacb (diff)
Add automatic JS license generation (#11810)
* Add automatic JS license generation Removed librejs file and replaced it with a plaintext file that is built from all JS dependencies that are included in the webpack build. It does not cover the few remaining statically vendored files and fomantic is added manually because it's not yet in the webpack build process. Fixes: https://github.com/go-gitea/gitea/issues/11630 * fix lint * remove jslicense, we're not librejs compatible any more * remove license.txt test as it depens on absent files * small optimization * trailing comma * localize and capitalize the word 'licenses' * reduce text to just 'Licenses' Co-authored-by: Lauris BH <lauris@nix.lv>
Diffstat (limited to 'webpack.config.js')
-rw-r--r--webpack.config.js30
1 files changed, 30 insertions, 0 deletions
diff --git a/webpack.config.js b/webpack.config.js
index 85a046892..09caeb402 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,5 +1,6 @@
const cssnano = require('cssnano');
const fastGlob = require('fast-glob');
+const wrapAnsi = require('wrap-ansi');
const FixStyleOnlyEntriesPlugin = require('webpack-fix-style-only-entries');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
@@ -11,6 +12,7 @@ const TerserPlugin = require('terser-webpack-plugin');
const VueLoaderPlugin = require('vue-loader/lib/plugin');
const {statSync} = require('fs');
const {resolve, parse} = require('path');
+const {LicenseWebpackPlugin} = require('license-webpack-plugin');
const {SourceMapDevToolPlugin} = require('webpack');
const glob = (pattern) => fastGlob.sync(pattern, {cwd: __dirname, absolute: true});
@@ -241,6 +243,34 @@ module.exports = {
new MonacoWebpackPlugin({
filename: 'js/monaco-[name].worker.js',
}),
+ new LicenseWebpackPlugin({
+ outputFilename: 'js/licenses.txt',
+ perChunkOutput: false,
+ addBanner: false,
+ skipChildCompilers: true,
+ modulesDirectories: [
+ resolve(__dirname, 'node_modules'),
+ ],
+ additionalModules: [
+ {
+ name: 'fomantic-ui',
+ directory: resolve(__dirname, 'node_modules/fomantic-ui'),
+ },
+ ],
+ renderLicenses: (modules) => {
+ const line = '-'.repeat(80);
+ return modules.map((module) => {
+ const {name, version} = module.packageJson;
+ const {licenseId, licenseText} = module;
+ const body = wrapAnsi(licenseText || '', 80);
+ return `${line}\n${name}@${version} - ${licenseId}\n${line}\n${body}`;
+ }).join('\n');
+ },
+ stats: {
+ warnings: false,
+ errors: true,
+ },
+ }),
],
performance: {
hints: false,