forked from openshift/console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.ts
181 lines (172 loc) · 5.11 KB
/
webpack.config.ts
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/* eslint-env node */
import * as webpack from 'webpack';
import * as path from 'path';
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
import * as ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
import * as VirtualModulesPlugin from 'webpack-virtual-modules';
import { resolvePluginPackages, getActivePluginsModule } from '@console/plugin-sdk/src/codegen';
import { Configuration as WebpackDevServerConfiguration } from 'webpack-dev-server';
interface Configuration extends webpack.Configuration {
devServer?: WebpackDevServerConfiguration;
}
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const NODE_ENV = process.env.NODE_ENV;
const HOT_RELOAD = process.env.HOT_RELOAD;
/* Helpers */
const extractCSS = new MiniCssExtractPlugin({ filename: 'app-bundle.[contenthash].css' });
const overpassTest = /overpass-.*\.(woff2?|ttf|eot|otf)(\?.*$|$)/;
const config: Configuration = {
entry: [
'./polyfills.js',
'./public/components/app.jsx',
'monaco-editor-core/esm/vs/editor/editor.worker.js',
],
output: {
path: path.resolve(__dirname, 'public/dist'),
publicPath: 'static/',
filename: '[name]-bundle.js',
chunkFilename: '[name]-[chunkhash].js',
},
devServer: {
writeToDisk: true,
progress: true,
hot: HOT_RELOAD !== 'false',
inline: HOT_RELOAD !== 'false',
},
resolve: {
extensions: ['.glsl', '.ts', '.tsx', '.js', '.jsx'],
},
node: {
fs: 'empty',
// eslint-disable-next-line camelcase
child_process: 'empty',
net: 'empty',
crypto: 'empty',
module: 'empty',
},
module: {
rules: [
{ test: /\.glsl$/, loader: 'raw!glslify' },
{
test: /(\.jsx?)|(\.tsx?)$/,
exclude: /node_modules\/(?!(bitbucket|ky)\/)/,
use: [
{ loader: 'cache-loader' },
{
loader: 'thread-loader',
options: {
// Leave one core spare for fork-ts-checker-webpack-plugin
workers: require('os').cpus().length - 1,
},
},
{
loader: 'ts-loader',
options: {
happyPackMode: true, // This implicitly enables transpileOnly! No type checking!
transpileOnly: true, // fork-ts-checker-webpack-plugin takes care of type checking
},
},
],
},
{
test: /\.s?css$/,
exclude: /node_modules\/(?!(@patternfly)\/).*/,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: './',
},
},
{ loader: 'cache-loader' },
{ loader: 'thread-loader' },
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'resolve-url-loader',
options: {
sourceMap: true,
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
outputStyle: 'compressed',
},
},
],
},
{
test: /\.css$/,
include: path.resolve(__dirname, './node_modules/monaco-editor'),
use: ['style-loader', 'css-loader'],
},
{
test: /\.(png|jpg|jpeg|gif|svg|woff2?|ttf|eot|otf)(\?.*$|$)/,
exclude: overpassTest,
loader: 'file-loader',
options: {
name: 'assets/[name].[ext]',
},
},
{
// Resolve to an empty module for overpass fonts included in SASS files.
// This way file-loader won't parse them. Make sure this is BELOW the
// file-loader rule.
test: overpassTest,
loader: 'null-loader',
},
],
},
optimization: {
splitChunks: {
chunks: 'all',
},
runtimeChunk: true,
},
plugins: [
new webpack.NormalModuleReplacementPlugin(/^lodash$/, 'lodash-es'),
new ForkTsCheckerWebpackPlugin({ checkSyntacticErrors: true }),
new HtmlWebpackPlugin({
filename: './tokener.html',
template: './public/tokener.html',
inject: false,
chunksSortMode: 'none',
}),
new HtmlWebpackPlugin({
filename: './index.html',
template: './public/index.html',
production: NODE_ENV === 'production',
chunksSortMode: 'none',
}),
new MonacoWebpackPlugin({
languages: ['yaml'],
}),
new webpack.IgnorePlugin(/prettier/),
extractCSS,
],
devtool: 'cheap-module-source-map',
stats: 'minimal',
};
/* Production settings */
if (NODE_ENV === 'production') {
config.output.filename = '[name]-bundle-[hash].min.js';
config.output.chunkFilename = '[name]-chunk-[chunkhash].min.js';
extractCSS.filename = '[name]-[chunkhash].min.css';
// Causes error in --mode=production due to scope hoisting
config.optimization.concatenateModules = false;
config.stats = 'normal';
}
/* Console plugin support */
config.plugins.push(
new VirtualModulesPlugin({
'node_modules/@console/active-plugins.js': getActivePluginsModule(resolvePluginPackages()),
}),
);
export default config;