-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·96 lines (89 loc) · 2.28 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
const logger = require("console");
const hasFlag = require("has-flag");
const path = require("path");
const RequireFrom = require("webpack-require-from");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
const { devServer, statusCode } = require("@metablock/server");
const PWD = process.cwd();
const STATIC_PATH = "/static/";
const DIRECTORY = path.resolve(PWD, `.${STATIC_PATH}`);
const mode = process.env.NODE_ENV === "production" ? "production" : "development";
const config = {
mode,
entry: {
luca: "./app/Index.tsx",
},
output: {
publicPath: STATIC_PATH,
path: DIRECTORY,
filename: "block.js",
chunkFilename: "[name].bundle.js",
libraryTarget: "umd",
},
devtool: "source-map",
optimization: {
minimize: mode === "production",
},
plugins: [
new RequireFrom({
variableName: "__bundle_url__",
}),
],
resolve: {
extensions: [".tsx", ".ts", ".js", ".jsx"],
alias: ["@mui", "react", "react-dom", "react-router-dom", "react-data-grid"].reduce(
(p, name) => {
p[name] = path.resolve(PWD, "node_modules", name);
return p;
},
{}
),
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: [/node_modules/, /third_party/, /server/],
use: {
loader: "ts-loader",
},
},
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" },
{
test: /\.(s?)css$/,
use: ["style-loader", "css-loader"],
//use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.(png|jpe?g|gif|woff|woff2|eot|ttf|svg)$/,
use: [
{
loader: "file-loader",
},
],
},
],
},
};
if (mode === "development") {
logger.log("Looks like we are in development mode");
config.devServer = devServer("https://lucasbardella.com", {
ssr: true,
docker: true,
ssrPlugins: [statusCode],
static: {
publicPath: STATIC_PATH,
directory: DIRECTORY,
},
hot: true,
port: 9085,
});
if (hasFlag("--watch") || hasFlag("-w")) {
const bundleAnaliser = new BundleAnalyzerPlugin({
openAnalyzer: false,
analyzerPort: 8833,
});
config.plugins.push(bundleAnaliser);
}
}
module.exports = config;