-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
132 lines (127 loc) · 4.37 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
const path = require("path");
const webpack = require("webpack");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const TerserPlugin = require("terser-webpack-plugin");
const CssMinimizerPlugin = require("css-minimizer-webpack-plugin");
const WebpackBar = require("webpackbar");
const LOCAL_II_URL = "http://rrkah-fqaaa-aaaaa-aaaaq-cai.localhost:8000"
const isDevelopment = process.env.NODE_ENV !== "production";
const frontendDirectory = "landing_assets";
const frontendDirectoryPath = path.join("src", frontendDirectory);
const asset_entry = path.join(frontendDirectoryPath, "src", "index.html");
module.exports = {
target: "web",
mode: isDevelopment ? "development" : "production",
entry: {
index: path.join(__dirname, asset_entry).replace(/\.html$/, ".jsx")
},
devtool: isDevelopment ? "source-map" : false,
optimization: {
minimize: !isDevelopment,
minimizer: [
new TerserPlugin(),
new CssMinimizerPlugin()
],
splitChunks: {
cacheGroups: {
vendor: {
name: "node_vendors",
test: /[\\/]node_modules[\\/]/,
chunks: "all",
},
},
}
},
resolve: {
extensions: [".js", ".ts", ".jsx", ".tsx"],
fallback: {
assert: require.resolve("assert/"),
buffer: require.resolve("buffer/"),
events: require.resolve("events/"),
stream: require.resolve("stream-browserify/"),
util: require.resolve("util/"),
},
modules: [
path.resolve('./node_modules'),
path.resolve('./')
],
},
output: {
filename: "[name].[contenthash].bundle.js",
path: path.join(__dirname, "dist", frontendDirectory),
publicPath: "/",
},
module: {
rules: [
{test: /\.(ts|tsx|jsx)$/, loader: "ts-loader"},
{test: /\.css$/, use: [MiniCssExtractPlugin.loader, 'css-loader']},
{
test: /\.(png|svg)$/,
type: 'asset',
parser: {
dataUrlCondition: {
maxSize: 6 * 1024,
},
},
},
{
test: /\.less$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{
loader: "less-loader",
options: {
lessOptions: {
javascriptEnabled: true,
paths: [
path.resolve(__dirname, "node_modules"),
path.resolve(__dirname, frontendDirectoryPath, "src", "css"),
]
},
}
}
]
}
]
},
plugins: [
new WebpackBar({profile: true}),
new MiniCssExtractPlugin({
filename: '[name].[contenthash].css',
chunkFilename: '[id].[contenthash].css',
}),
new HtmlWebpackPlugin({
template: path.join(__dirname, asset_entry),
cache: false
}),
new webpack.EnvironmentPlugin({
NODE_ENV: "development",
II_URL: isDevelopment ? LOCAL_II_URL : "https://identity.ic0.app",
NFID_II_URL: "https://nfid.one/authenticate/?applicationName=Canistergeek&applicationLogo=https%3A%2F%2Fxcxtd-2qaaa-aaaah-qabfa-cai.raw.ic0.app%2Ffavicon-64.svg#authorize",
}),
new webpack.ProvidePlugin({
Buffer: [require.resolve("buffer/"), "Buffer"],
process: require.resolve("process/browser"),
}),
],
// proxy /api to port 8000 during development
devServer: {
proxy: {
"/api": {
target: "http://localhost:8000",
changeOrigin: true,
pathRewrite: {
"^/api": "/api",
},
},
},
port: 3001,
hot: true,
host: "0.0.0.0",
watchFiles: [path.resolve(__dirname, frontendDirectoryPath)],
liveReload: true,
historyApiFallback: true,
},
};