-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.cjs
108 lines (106 loc) · 3.22 KB
/
webpack.config.cjs
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
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const {
CleanWebpackPlugin
} = require("clean-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const plugins = [
new CleanWebpackPlugin(),
new MiniCssExtractPlugin(),
new HtmlWebpackPlugin({
template: "./src/index.html"
}),
];
module.exports = (enc, arg) => {
return {
mode: arg.mode,
entry: "./src/index.ts",
output: {
// output path is required for `clean-webpack-plugin`
path: path.resolve(__dirname, "dist"),
// this places all images processed in an image folder
assetModuleFilename: "images/[hash][ext][query]"
},
module: {
rules: [{
test: /\.(s[ac]|c)ss$/i,
use: [{
loader: MiniCssExtractPlugin.loader,
options: {
// This is required for asset imports in CSS, such as url()
publicPath: ""
},
},
"css-loader",
"postcss-loader",
// according to the docs, sass-loader should be at the bottom, which
// loads it first to avoid prefixes in your sourcemaps and other issues.
"sass-loader"
]
},
{
// Load model
test: /\.(json|bin)$/,
type: "asset",
//include: path.resolve(__dirname, 'MLModel/ModelTrainer/decoderModel'),
use: [{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'model/',
},
}]
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
/**
* The `type` setting replaces the need for "url-loader"
* and "file-loader" in Webpack 5.
*
* setting `type` to "asset" will automatically pick between
* outputing images to a file, or inlining them in the bundle as base64
* with a default max inline size of 8kb
*/
type: "asset",
/**
* If you want to inline larger images, you can set
* a custom `maxSize` for inline like so:
*/
// parser: {
// dataUrlCondition: {
// maxSize: 30 * 1024,
// },
// },
},
{
test: /\.(ts|js)x?$/,
exclude: /node_modules/,
use: {
loader: "babel-loader",
options: {
/**
* From the docs: When set, the given directory will be used
* to cache the results of the loader. Future webpack builds
* will attempt to read from the cache to avoid needing to run
* the potentially expensive Babel recompilation process on each run.
*/
cacheDirectory: true,
}
}
}
]
},
plugins: plugins,
// Temporary workaround for 'browserslist' bug that is being patched in the near future
target: arg.env === "production" ? "browserslist" : "web",
devtool: "source-map",
resolve: {
extensions: [".ts", ".tsx", ".js", ".jsx"]
},
devServer: {
static: "./dist",
port: 4200,
hot: true,
}
}
}