From 9fd1cf7f3f7e9a547fa6329e93f2d190970052e2 Mon Sep 17 00:00:00 2001 From: Martin Pitt Date: Sun, 22 Nov 2020 12:35:23 +0100 Subject: [PATCH] webpack: Simplify copied files As `files` is now the only entry in `info`, rename it to a `copy_files` constant, and drop `info` completely. Drop the "qualify" loop and add the src/ subdirectory to the path directly. This is more explicit, thus easier to understand, and simpler. Drop the now unused "vpath" function. --- webpack.config.js | 45 +++++++-------------------------------------- 1 file changed, 7 insertions(+), 38 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index c5b83b7..6223502 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,53 +1,22 @@ const path = require("path"); const copy = require("copy-webpack-plugin"); const extract = require("mini-css-extract-plugin"); -const fs = require("fs"); const webpack = require("webpack"); const CompressionPlugin = require("compression-webpack-plugin"); -/* These can be overridden, typically from the Makefile.am */ -const srcdir = (process.env.SRCDIR || __dirname) + path.sep + "src"; -const builddir = (process.env.SRCDIR || __dirname); -const section = process.env.ONLYDIR || null; const nodedir = path.resolve((process.env.SRCDIR || __dirname), "node_modules"); /* A standard nodejs and webpack pattern */ var production = process.env.NODE_ENV === 'production'; -var info = { - files: [ - "index.html", - "manifest.json", - ], -}; +// Non-JS files which are copied verbatim to dist/ +const copy_files = [ + "./src/index.html", + "./src/manifest.json", +]; -/* - * Note that we're avoiding the use of path.join as webpack and nodejs - * want relative paths that start with ./ explicitly. - * - * In addition we mimic the VPATH style functionality of GNU Makefile - * where we first check builddir, and then srcdir. - */ - -function vpath(/* ... */) { - var filename = Array.prototype.join.call(arguments, path.sep); - var expanded = builddir + path.sep + filename; - if (fs.existsSync(expanded)) - return expanded; - expanded = srcdir + path.sep + filename; - return expanded; -} - -/* Qualify all the paths in files listed */ -var files = []; -info.files.forEach(function(value) { - if (!section || value.indexOf(section) === 0) - files.push({ from: vpath("src", value), to: value }); -}); -info.files = files; - -var plugins = [ - new copy({ patterns: info.files }), +const plugins = [ + new copy({ patterns: copy_files }), new extract({filename: "[name].css"}) ];