This repository has been archived by the owner on Jul 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
117 lines (111 loc) · 2.76 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
/* eslint-disable */
const path = require('path');
const express = require('express');
const Dotenv = require('dotenv-webpack');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const extensions = ['.tsx', '.jsx', '.js', '.ts', '.json'];
const mockEndepunkter = require('./mock/mockEndepunkter');
const setupDev = async (app, compiler) => {
mockEndepunkter(app);
app.use('/static', express.static(path.resolve(__dirname, 'dist')));
app.use('*', (req, res) => {
const filename = path.join(compiler.outputPath, 'index.html');
compiler.outputFileSystem.readFile(filename, (err, result) => {
if (err) {
res.status(404).sendFile(path.resolve(__dirname, 'public/error.html'));
return;
}
res.set('Content-Type', 'text/html');
res.send(result);
res.end();
});
});
};
module.exports = {
entry: './js/index.tsx',
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/static/',
filename: 'bundle.js',
clean: true,
},
mode: 'development',
devtool: 'eval-source-map',
resolve: {
alias: {
react: path.join(__dirname, 'node_modules', 'react'),
},
plugins: [
new TsconfigPathsPlugin({
extensions,
}),
],
extensions,
},
module: {
rules: [
{
test: /\.less$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
options: {
postcssOptions: {
plugins: [['postcss-preset-env']],
},
},
},
{
loader: 'less-loader',
},
],
},
{
test: /\.(js|ts|tsx)$/,
use: { loader: 'babel-loader' },
exclude: /node_modules/,
},
{
test: /\.(vtt)$/,
type: 'asset/inline',
},
{
test: /\.((woff2?|svg)(\?v=[0-9]\.[0-9]\.[0-9]))|(woff2?|svg|jpe?g|png|gif|ico|mp4)$/,
type: 'asset/resource',
},
],
},
devServer: {
static: {
directory: path.join(__dirname, 'dist'),
},
port: 8080,
onAfterSetupMiddleware: function (devServer) {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
setupDev(devServer.app, devServer.compiler);
},
},
plugins: [
new HtmlWebpackPlugin({
template: 'public/index.html',
filename: 'index.html',
hash: true,
}),
new Dotenv(),
new ForkTsCheckerWebpackPlugin({
eslint: {
files: './js/**/*.{ts,tsx,js,jsx}',
},
}),
],
};