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.
129 lines
3.8 KiB
JavaScript
129 lines
3.8 KiB
JavaScript
const path = require("path");
|
|
const copy = require("copy-webpack-plugin");
|
|
const extract = require("mini-css-extract-plugin");
|
|
const webpack = require("webpack");
|
|
const CompressionPlugin = require("compression-webpack-plugin");
|
|
|
|
const nodedir = path.resolve((process.env.SRCDIR || __dirname), "node_modules");
|
|
|
|
/* A standard nodejs and webpack pattern */
|
|
var production = process.env.NODE_ENV === 'production';
|
|
|
|
// Non-JS files which are copied verbatim to dist/
|
|
const copy_files = [
|
|
"./src/index.html",
|
|
"./src/manifest.json",
|
|
];
|
|
|
|
const plugins = [
|
|
new copy({ patterns: copy_files }),
|
|
new extract({filename: "[name].css"})
|
|
];
|
|
|
|
/* Only minimize when in production mode */
|
|
if (production) {
|
|
plugins.unshift(new CompressionPlugin({
|
|
test: /\.(js|html)$/,
|
|
minRatio: 0.9,
|
|
deleteOriginalAssets: true
|
|
}));
|
|
}
|
|
|
|
/* keep this in sync with cockpit.git */
|
|
var babel_loader = {
|
|
loader: "babel-loader",
|
|
options: {
|
|
presets: [
|
|
["@babel/env", {
|
|
"targets": {
|
|
"chrome": "57",
|
|
"firefox": "52",
|
|
"safari": "10.3",
|
|
"edge": "16",
|
|
"opera": "44"
|
|
}
|
|
}],
|
|
"@babel/preset-react"
|
|
]
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
mode: production ? 'production' : 'development',
|
|
resolve: {
|
|
modules: [ nodedir ],
|
|
},
|
|
resolveLoader: {
|
|
modules: [ nodedir, path.resolve(__dirname, 'src/lib') ],
|
|
},
|
|
watchOptions: {
|
|
ignored: /node_modules/,
|
|
},
|
|
entry: {
|
|
index: "./src/index.js",
|
|
},
|
|
// cockpit.js gets included via <script>, everything else should be bundled
|
|
externals: { "cockpit": "cockpit" },
|
|
devtool: "source-map",
|
|
module: {
|
|
rules: [
|
|
{
|
|
enforce: 'pre',
|
|
exclude: /node_modules/,
|
|
loader: 'eslint-loader',
|
|
test: /\.(js|jsx)$/
|
|
},
|
|
{
|
|
exclude: /node_modules/,
|
|
use: babel_loader,
|
|
test: /\.(js|jsx)$/
|
|
},
|
|
/* HACK: remove unwanted fonts from PatternFly's css */
|
|
{
|
|
test: /patternfly-4-cockpit.scss$/,
|
|
use: [
|
|
extract.loader,
|
|
{
|
|
loader: 'css-loader',
|
|
options: {
|
|
sourceMap: true,
|
|
url: false
|
|
}
|
|
},
|
|
{
|
|
loader: 'string-replace-loader',
|
|
options: {
|
|
multiple: [
|
|
{
|
|
search: /src:url\("patternfly-icons-fake-path\/pficon[^}]*/g,
|
|
replace: "src:url('fonts/patternfly.woff')format('woff');",
|
|
},
|
|
{
|
|
search: /@font-face[^}]*patternfly-fonts-fake-path[^}]*}/g,
|
|
replace: '',
|
|
},
|
|
]
|
|
},
|
|
},
|
|
'sassc-loader',
|
|
]
|
|
},
|
|
{
|
|
test: /\.s?css$/,
|
|
exclude: /patternfly-4-cockpit.scss/,
|
|
use: [
|
|
extract.loader,
|
|
{
|
|
loader: 'css-loader',
|
|
options: {
|
|
sourceMap: true,
|
|
url: false
|
|
}
|
|
},
|
|
'sassc-loader',
|
|
]
|
|
},
|
|
]
|
|
},
|
|
plugins: plugins
|
|
}
|