monkeytype/frontend/webpack.config.js
Rizwan Mustafa 759ff88de7
Created webpack config file for detecting circular imports (#2463)
* Created webpack config file for detecting circular imports

* missing packages, added script to run webpack to find circular dependencies

Co-authored-by: Miodec <bartnikjack@gmail.com>
2022-02-10 17:21:24 +01:00

47 lines
1.6 KiB
JavaScript

const path = require("path");
const CircularDependencyPlugin = require("circular-dependency-plugin");
module.exports = {
mode: "development", // Change to 'production' for production
devtool: false, // no SourceMap
entry: "./src/js/index.js",
resolve: {
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
},
},
output: {
path: path.resolve(__dirname, "public/js/"),
filename: "monkeytype.js",
},
plugins: [
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /node_modules/,
// include specific files based on a RegExp
include: /./,
// add errors to webpack instead of warnings
failOnError: false,
// allow import cycles that include an asyncronous import,
// e.g. via import(/* webpackMode: "weak" */ './file.js')
allowAsyncCycles: false,
// set the current working directory for displaying module paths
cwd: process.cwd(),
onStart() {
console.log("start detecting webpack modules cycles");
},
// `onDetected` is called for each module that is cyclical
onDetected({ module: _webpackModuleRecord, paths, compilation }) {
// `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
compilation.errors.push(new Error(paths.join(" -> ")));
},
// `onEnd` is called before the cycle detection ends
onEnd() {
console.log("end detecting webpack modules cycles");
},
}),
],
};