UNPKG

2.01 kBJavaScriptView Raw
1const path = require("path");
2const fs = require("fs");
3const MiniCssExtractPlugin = require("mini-css-extract-plugin");
4const common = require("@finos/perspective/src/config/common.config.js");
5const FixStyleOnlyEntriesPlugin = require("webpack-fix-style-only-entries");
6const THEMES = fs.readdirSync(path.resolve(__dirname, "..", "themes"));
7
8function try_delete(name) {
9 const filePath = path.resolve(__dirname, "..", "..", "dist", "umd", name);
10 if (fs.existsSync(filePath)) {
11 fs.unlinkSync(filePath);
12 }
13}
14
15function reducer(obj, key, val) {
16 obj[key] = val;
17 return obj;
18}
19
20module.exports = common({}, config => {
21 config.plugins.push(
22 new MiniCssExtractPlugin({
23 splitChunks: {
24 chunks: "all"
25 },
26 filename: "[name].css"
27 })
28 );
29
30 config.plugins.push({
31 apply: compiler => {
32 compiler.hooks.afterEmit.tap("AfterEmitPlugin", () => {
33 for (const theme of THEMES) {
34 try_delete(theme.replace("less", "js"));
35 try_delete(theme.replace("less", "js.map"));
36 try_delete(theme.replace("less", "css.map"));
37 }
38 });
39 }
40 });
41
42 config.plugins.push(new FixStyleOnlyEntriesPlugin());
43 config.module.rules.push({
44 test: /\.(woff|ttf|eot|svg|woff2)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
45 loader: "base64-font-loader"
46 });
47
48 config.module.rules.push({
49 test: /themes[\\/].+?\.less$/,
50 use: [{loader: MiniCssExtractPlugin.loader}, "css-loader", "less-loader"]
51 });
52
53 return Object.assign(config, {
54 entry: THEMES.reduce((obj, theme) => reducer(obj, theme.replace(".less", ""), path.resolve(__dirname, "..", "themes", theme)), {"perspective-viewer": "./dist/cjs/perspective-viewer.js"}),
55 output: {
56 filename: "[name].js",
57 libraryTarget: "umd",
58 path: path.resolve(__dirname, "../../dist/umd")
59 }
60 });
61});