Skip to content

Commit

Permalink
fix: require optional dependency conditionally
Browse files Browse the repository at this point in the history
prettier and webpack are only available in dev environment.
  • Loading branch information
caugner committed Nov 10, 2022
1 parent 46d0bd9 commit 1febbdf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
5 changes: 2 additions & 3 deletions content/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import path from "path";
import childProcess from "child_process";

import LRU from "lru-cache";
import prettier from "prettier";

import { CONTENT_ROOT, CONTENT_TRANSLATED_ROOT } from "../libs/env";
import { slugToFolder as _slugToFolder } from "../libs/slug-utils";
Expand Down Expand Up @@ -107,7 +105,8 @@ export function execGit(args, opts: { cwd?: string } = {}, root = null) {
export function toPrettyJSON(value) {
const json = JSON.stringify(value, null, 2) + "\n";
try {
return prettier.format(json, { parser: "json" });
// eslint-disable-next-line n/no-unpublished-require
return require("prettier").format(json, { parser: "json" });
} catch (e) {
return json;
}
Expand Down
10 changes: 6 additions & 4 deletions server/dev.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import webpack from "webpack";
import webpackDevMiddleware from "webpack-dev-middleware";
import webpackHotMiddleware from "webpack-hot-middleware";
import { WebpackConfiguration } from "webpack-dev-server";
import type { WebpackConfiguration } from "webpack-dev-server";

export const devMiddlewares = [];

if (process.env.NODE_ENV === "development") {
/* eslint-disable n/no-unpublished-require */
const webpack = require("webpack");
const webpackDevMiddleware = require("webpack-dev-middleware");
const webpackHotMiddleware = require("webpack-hot-middleware");

const webpackConfig: WebpackConfiguration = {
entry: {
app: [
Expand Down

0 comments on commit 1febbdf

Please sign in to comment.