monkeytype/frontend/webpack.config.js
Rizwan Mustafa 1877cc31e7
(Draft) Replace Browserify with Webpack (Draft) (#2461) by rizwanmustafa
* Replaced browserify with webpack

* Modified gulpfile and webpack config

* Removed attempts of using undefined variables and functions

* fixed some incorrect changes

* setfunbox fix

* Added fallback for crypto-browserify and stream-browserify

* added circular dependency detection

* Created production tasks for gulp and updated webpack config

* fixed circular dependency in misc

* not failing on circular dependency

* Removed unused imports

* Added babel loader and plugins to webpack

* Removed unused dependencies and removed babel's plugins

* Workaround for test logic import in random quote

* Created a separate webpack config file for production

* Changed relative paths to absolute ones in webpack

* Added colored output for circular import number

* Removed comment from .eslintrc.json

* Added eslint plugin to webpack

* Moved 'buffer' and 'stream-browserify' to devDependencies

* Started using promises in webpack tasks

* Removed unused dependencies

* Updated package-lock.json

* Removed eslint plugin from webpack and added circular dependency detection in dev config as well

* Removed unrelated changes

* Updated production build command

* Added ability for webpack to be run with typescript conversion of project in process

* added gulp typscript dev dependency

* using const

* modified console logs on circular imports

* missing dev dependency

Co-authored-by: Miodec <bartnikjack@gmail.com>
2022-02-12 14:47:36 +01:00

49 lines
1.7 KiB
JavaScript

const path = require("path");
const CircularDependencyPlugin = require("circular-dependency-plugin");
let circularImportNum = 0;
module.exports = {
mode: "development", // Change to 'production' for production
devtool: false,
entry: path.resolve(__dirname, "dist/index.js"),
resolve: {
fallback: {
crypto: require.resolve("crypto-browserify"),
stream: require.resolve("stream-browserify"),
buffer: require.resolve("buffer"),
},
},
output: {
path: path.resolve(__dirname, "public/js/"),
filename: "monkeytype.js",
},
plugins: [
// Ensure that there are no circular dependencies
new CircularDependencyPlugin({
exclude: /node_modules/,
include: /./,
failOnError: true,
allowAsyncCycles: false, // Allow async webpack imports
cwd: process.cwd(), // set current working dir for displaying module paths
// `onDetected` is called for each module that is cyclical
onDetected({ module: _webpackModuleRecord, paths }) {
// `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
circularImportNum += 1;
console.log(
"\u001b[31mCircular import found: \u001b[0m" +
paths.join("\u001b[31m -> \u001b[0m")
);
},
// `onEnd` is called before the cycle detection ends
onEnd() {
let coloredImportNum = "";
if (circularImportNum === 0)
coloredImportNum = `\u001b[32m${circularImportNum}\u001b[0m`;
else coloredImportNum = `\u001b[31m${circularImportNum}\u001b[0m`;
console.log(`Found ${coloredImportNum} circular imports`);
},
}),
],
};