forked from eclipse-che/che-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.dev.js
119 lines (115 loc) · 3.09 KB
/
webpack.config.dev.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
/*
* Copyright (c) 2018-2020 Red Hat, Inc.
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc. - initial API and implementation
*/
const merge = require('webpack-merge');
const path = require('path');
const webpack = require('webpack');
const CleanTerminalPlugin = require('clean-terminal-webpack-plugin');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const StylelintPlugin = require('stylelint-webpack-plugin');
const common = require('./webpack.config.common');
module.exports = env => {
const proxyTarget = env && env.server;
if (!proxyTarget) {
throw new Error('Che server URL is not set. Argument "--env.server=" is mandatory in development mode.');
}
const headers = {
origin: proxyTarget,
};
if (env && env.token) {
headers['Authorization'] = `Bearer ${env.token}`;
}
return merge(common, {
mode: 'development',
module: {
rules: [
{
enforce: 'pre',
test: /\.(tsx|ts|jsx|js)$/,
loader: 'source-map-loader',
include: path.resolve(__dirname, 'src'),
},
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: {
auto: true,
localIdentName: '[path][name]__[local]',
},
},
},
],
},
]
},
plugins: [
new webpack.DefinePlugin({
__isBrowser__: "true",
'process.env.ENVIRONMENT': JSON.stringify('development'),
'process.env.SERVER': JSON.stringify(env.server),
}),
new webpack.HotModuleReplacementPlugin(),
new CleanTerminalPlugin(),
new HardSourceWebpackPlugin(),
new StylelintPlugin({
context: path.join(__dirname, 'src'),
emitWarning: true,
files: '**/*.css',
lintDirtyModulesOnly: true,
}),
],
output: {
chunkFilename: undefined,
},
optimization: {
minimize: false,
removeAvailableModules: false,
removeEmptyChunks: false,
splitChunks: false,
},
devtool: 'eval-cheap-module-source-map',
devServer: {
clientLogLevel: 'debug',
contentBase: path.join(__dirname, 'assets'),
contentBasePublicPath: '/assets/',
disableHostCheck: true,
host: 'localhost',
hot: true,
open: false,
port: 3000,
stats: 'errors-warnings',
// writeToDisk: true,
proxy: {
'/api/websocket': {
target: proxyTarget,
ws: true,
secure: false,
changeOrigin: true,
headers: headers
},
'/api': {
target: proxyTarget,
secure: false,
changeOrigin: true,
headers: headers,
},
},
},
watchOptions: {
aggregateTimeout: 1000,
ignored: /node_modules/,
},
});
};