-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathwebpack.config.development.js
More file actions
93 lines (84 loc) · 3.04 KB
/
webpack.config.development.js
File metadata and controls
93 lines (84 loc) · 3.04 KB
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
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 CodegenWatchPlugin = require('./src/codegen/CodegenWatchPlugin');
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(),
new CodegenWatchPlugin(),
];
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';
const enableErrorsOverlay = !('WEBPACK_ERRORS_OVERLAY' in env) || env.WEBPACK_ERRORS_OVERLAY === '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,
}),
]
: [],
},
plugins,
devServer: {
historyApiFallback: true,
allowedHosts: 'all',
hot: true,
headers: {
'Access-Control-Allow-Origin': '*',
'X-Altinn-Frontend-Branch': branchName,
},
// https://github.com/webpack/webpack-dev-server/issues/5446#issuecomment-2768816082
setupMiddlewares: (middlewares) => {
return middlewares.filter((middleware) => middleware.name !== 'cross-origin-header-check');
},
client: {
overlay: {
errors: enableErrorsOverlay,
warnings: false,
},
},
static: [
{
directory: path.join(__dirname, 'schemas'),
publicPath: '/schemas',
},
],
},
};