thelounge/webpack.config-test.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

"use strict";
2019-11-12 16:51:40 +01:00
const webpack = require("webpack");
2020-03-22 11:47:41 +01:00
const fs = require("fs");
2019-11-12 16:51:40 +01:00
const path = require("path");
2020-03-22 11:47:41 +01:00
const VueLoaderPlugin = require("vue-loader/lib/plugin");
const config = require("./webpack.config.js");
2020-03-22 11:47:41 +01:00
const testFile = path.resolve(__dirname, "test/public/testclient.js");
if (fs.existsSync(testFile)) {
fs.unlinkSync(testFile);
}
config.target = "node";
2018-09-04 22:18:17 +02:00
config.devtool = "eval";
2020-03-22 11:47:41 +01:00
config.stats = "errors-only";
config.output.path = path.resolve(__dirname, "test/public");
config.entry = {
"testclient.js": [path.resolve(__dirname, "test/client/index.js")],
};
// Add the istanbul plugin to babel-loader options
for (const rule of config.module.rules) {
if (rule.use.loader === "babel-loader") {
2019-07-17 11:33:59 +02:00
rule.use.options.plugins = ["istanbul"];
}
}
2018-01-25 19:32:28 +01:00
// `optimization.splitChunks` is incompatible with a `target` of `node`. See:
// - https://github.com/zinserjan/mocha-webpack/issues/84
// - https://github.com/webpack/webpack/issues/6727#issuecomment-372589122
config.optimization.splitChunks = false;
2020-03-22 11:47:41 +01:00
// Disable plugins like copy files, it is not required
config.plugins = [
new VueLoaderPlugin(),
2019-11-12 16:51:40 +01:00
2020-03-22 11:47:41 +01:00
// Client tests that require Vue may end up requireing socket.io
2019-11-12 16:51:40 +01:00
new webpack.NormalModuleReplacementPlugin(
/js(\/|\\)socket\.js/,
path.resolve(__dirname, "scripts/noop.js")
2020-03-22 11:47:41 +01:00
),
// "Fixes" Critical dependency: the request of a dependency is an expression
new webpack.ContextReplacementPlugin(/vue-server-renderer$/),
];
2019-11-12 16:51:40 +01:00
module.exports = config;