2022-02-11 00:21:24 +08:00
|
|
|
const path = require("path");
|
|
|
|
const CircularDependencyPlugin = require("circular-dependency-plugin");
|
|
|
|
|
2022-02-12 21:47:36 +08:00
|
|
|
let circularImportNum = 0;
|
|
|
|
|
2022-02-11 00:21:24 +08:00
|
|
|
module.exports = {
|
|
|
|
mode: "development", // Change to 'production' for production
|
2022-02-12 21:47:36 +08:00
|
|
|
devtool: false,
|
2022-02-13 07:10:19 +08:00
|
|
|
entry: path.resolve(__dirname, "src/scripts/index.ts"),
|
2022-02-11 00:21:24 +08:00
|
|
|
resolve: {
|
|
|
|
fallback: {
|
|
|
|
crypto: require.resolve("crypto-browserify"),
|
|
|
|
stream: require.resolve("stream-browserify"),
|
2022-02-12 21:47:36 +08:00
|
|
|
buffer: require.resolve("buffer"),
|
2022-02-11 00:21:24 +08:00
|
|
|
},
|
2022-02-12 23:33:39 +08:00
|
|
|
extensions: [".ts", ".js"],
|
2022-02-11 00:21:24 +08:00
|
|
|
},
|
|
|
|
output: {
|
2022-02-12 23:27:49 +08:00
|
|
|
path: path.resolve(__dirname, "public/js/"),
|
2022-02-11 00:21:24 +08:00
|
|
|
filename: "monkeytype.js",
|
|
|
|
},
|
2022-02-12 23:33:39 +08:00
|
|
|
module: {
|
|
|
|
rules: [{ test: /\.tsx?$/, loader: "ts-loader" }],
|
|
|
|
},
|
2022-02-11 00:21:24 +08:00
|
|
|
plugins: [
|
2022-02-12 21:47:36 +08:00
|
|
|
// Ensure that there are no circular dependencies
|
2022-02-11 00:21:24 +08:00
|
|
|
new CircularDependencyPlugin({
|
|
|
|
exclude: /node_modules/,
|
|
|
|
include: /./,
|
2022-02-12 21:47:36 +08:00
|
|
|
failOnError: true,
|
|
|
|
allowAsyncCycles: false, // Allow async webpack imports
|
|
|
|
cwd: process.cwd(), // set current working dir for displaying module paths
|
2022-02-11 00:21:24 +08:00
|
|
|
// `onDetected` is called for each module that is cyclical
|
2022-02-12 21:47:36 +08:00
|
|
|
onDetected({ module: _webpackModuleRecord, paths }) {
|
2022-02-11 00:21:24 +08:00
|
|
|
// `paths` will be an Array of the relative module paths that make up the cycle
|
|
|
|
// `module` will be the module record generated by webpack that caused the cycle
|
2022-02-12 21:47:36 +08:00
|
|
|
circularImportNum += 1;
|
|
|
|
console.log(
|
|
|
|
"\u001b[31mCircular import found: \u001b[0m" +
|
|
|
|
paths.join("\u001b[31m -> \u001b[0m")
|
|
|
|
);
|
2022-02-11 00:21:24 +08:00
|
|
|
},
|
|
|
|
// `onEnd` is called before the cycle detection ends
|
|
|
|
onEnd() {
|
2022-02-12 21:47:36 +08:00
|
|
|
let coloredImportNum = "";
|
|
|
|
if (circularImportNum === 0)
|
|
|
|
coloredImportNum = `\u001b[32m${circularImportNum}\u001b[0m`;
|
|
|
|
else coloredImportNum = `\u001b[31m${circularImportNum}\u001b[0m`;
|
|
|
|
console.log(`Found ${coloredImportNum} circular imports`);
|
2022-02-11 00:21:24 +08:00
|
|
|
},
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
};
|