forked from Altinn/app-frontend-react
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.development.js
104 lines (95 loc) · 3.02 KB
/
webpack.config.development.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
/* eslint-disable no-console */
const env = require('dotenv').config().parsed ?? {};
const path = require('path');
const fs = require('fs');
const ForkTsCheckerNotifierWebpackPlugin = require('fork-ts-checker-notifier-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { EsbuildPlugin } = require('esbuild-loader');
const common = require('./webpack.common');
const enableNotifier = !('WEBPACK_SILENT' in env) || env.WEBPACK_SILENT === 'false';
const plugins = [...common.plugins, new ReactRefreshWebpackPlugin()];
if (enableNotifier) {
plugins.push(new ForkTsCheckerNotifierWebpackPlugin());
}
const enableSourceMaps = !('WEBPACK_SOURCE_MAPS' in env) || env.WEBPACK_SOURCE_MAPS === 'true';
const enableMinify = !('WEBPACK_MINIFY' in env) || env.WEBPACK_MINIFY === 'true';
console.log('Starting Altinn 3 app-frontend-react development server');
console.log('See template.env for available environment variables and how to set them');
console.log('');
console.log('Current settings:');
console.log('WEBPACK_SILENT =', !enableNotifier);
console.log('WEBPACK_SOURCE_MAPS =', enableSourceMaps);
console.log('WEBPACK_MINIFY =', enableMinify);
console.log('====================================');
// Find the git current branch name from .git/HEAD. This is used in LocalTest to show you the current branch name.
// We can't just read this when starting, as you may want to switch branch while the dev server is running. This
// will be called every time you refresh/reload the dev server.
const branchName = {
toString() {
const hasGitFolder = fs.existsSync('.git');
const gitHead = hasGitFolder ? fs.readFileSync('.git/HEAD', 'utf-8') : '';
const ref = gitHead.match(/ref: refs\/heads\/([^\n]+)/);
return ref ? ref[1] : 'unknown-branch';
},
};
module.exports = {
...common,
mode: 'development',
devtool: enableSourceMaps ? 'inline-source-map' : false,
performance: {
// We should fix this here: https://github.com/Altinn/app-frontend-react/issues/1597
hints: false,
},
optimization: {
minimizer: enableMinify
? [
new EsbuildPlugin({
target: 'es2020',
css: true,
}),
]
: [],
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
loader: 'esbuild-loader',
options: {
target: 'es2020',
},
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.png$/,
type: 'asset/resource',
},
],
},
plugins,
devServer: {
historyApiFallback: true,
allowedHosts: 'all',
hot: true,
headers: {
'Access-Control-Allow-Origin': '*',
'X-Altinn-Frontend-Branch': branchName,
},
client: {
overlay: {
errors: true,
warnings: false,
},
},
static: [
{
directory: path.join(__dirname, 'schemas'),
publicPath: '/schemas',
},
],
},
};