-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
67 lines (60 loc) · 1.7 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const express = require("express");
const fs = require("fs/promises");
const path = require("path");
const {getTreeNode} = require('./lib/node')
module.exports = {
entry: [
// Runtime code for hot module replacement
"webpack/hot/dev-server.js",
// Dev server client for web socket transport, hot and live reload logic
"webpack-dev-server/client/index.js?hot=true&live-reload=true",
__dirname + "/demo/index.tsx",
],
output: {
filename: "bundle.js",
path: __dirname + "/dist",
},
mode: "development",
// Enable sourcemaps for debugging webpack's output.
devtool: "source-map",
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"],
},
devServer: {
open: true,
compress: true,
port: 9000,
onBeforeSetupMiddleware: function (devServer) {
if (!devServer) {
throw new Error("webpack-dev-server is not defined");
}
devServer.app.use(express.json());
devServer.app.get("/root", async (req, res) => {
res.send(await getTreeNode('.'));
});
},
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{ test: /\.jsx?$/, loader: "babel-loader" },
{ test: /\.tsx?$/, loader: "ts-loader" },
{
test: /\.css$/i,
use: ["style-loader", "css-loader"],
},
],
},
plugins: [
new webpack.ProvidePlugin({
process: "process/browser",
}),
new HtmlWebpackPlugin({
template: __dirname + "/index.html",
title: "React File Tree",
}),
],
};