MCPcopy
hub / github.com/webpack/webpack-dev-server / setup

Function setup

examples/util.js:15–109  ·  view source on GitHub ↗
(config, callerUrl)

Source from the content-addressed store, hash-verified

13 * @returns {object} normalized webpack config
14 */
15export function setup(config, callerUrl) {
16 const defaults = { mode: "development", plugins: [], devServer: {} };
17
18 if (config.entry) {
19 if (typeof config.entry === "string") {
20 config.entry = path.resolve(config.entry);
21 } else if (Array.isArray(config.entry)) {
22 config.entry = config.entry.map((entry) => path.resolve(entry));
23 } else if (typeof config.entry === "object") {
24 for (const [key, value] of Object.entries(config.entry)) {
25 config.entry[key] = path.resolve(value);
26 }
27 }
28 }
29
30 const result = { ...defaults, ...config };
31 const onBeforeSetupMiddleware = ({ app }) => {
32 app.use("/.assets/", (req, res, next) => {
33 if (req.method !== "GET" && req.method !== "HEAD") {
34 next();
35 return;
36 }
37
38 res.setHeader("Content-Type", mime.lookup(req.url));
39
40 const filename = path.join(__dirname, "/.assets/", req.url);
41 const stream = fs.createReadStream(filename);
42
43 stream.pipe(res);
44 });
45 };
46 const renderer = new marked.Renderer();
47 const { heading } = renderer;
48 const markedOptions = {
49 gfm: true,
50 tables: true,
51 breaks: false,
52 pedantic: false,
53 sanitize: false,
54 sanitizer: null,
55 mangle: true,
56 smartLists: false,
57 silent: false,
58 langPrefix: "lang-",
59 smartypants: false,
60 headerPrefix: "",
61 renderer,
62 xhtml: false,
63 };
64 const readme = fs.readFileSync("README.md", "utf8");
65
66 let exampleTitle = "";
67
68 renderer.heading = function headingProxy(text, level, raw, slugger) {
69 if (level === 1 && !exampleTitle) {
70 exampleTitle = text;
71 }
72

Callers 15

webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90
webpack.config.jsFile · 0.90

Calls 1

onBeforeSetupMiddlewareFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…