forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
170 lines (167 loc) · 5.08 KB
/
webpack.common.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
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
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
const packageName = require('../../package.json').name;
const CorsWorkerPlugin = require('./plugins/CorsWorkerPlugin');
module.exports = {
target: 'web',
entry: {
app: './public/app/index.ts',
},
output: {
clean: true,
path: path.resolve(__dirname, '../../public/build'),
filename: '[name].[contenthash].js',
// Keep publicPath relative for host.com/grafana/ deployments
publicPath: 'public/build/',
library: `${packageName}-[name]`,
libraryTarget: 'umd',
chunkLoadingGlobal: `webpackJsonp_${packageName}`,
},
resolve: {
extensions: ['.ts', '.tsx', '.es6', '.js', '.json', '.svg'],
alias: {
// some of data source plugins use global Prism object to add the language definition
// we want to have same Prism object in core and in grafana/ui
prismjs: require.resolve('prismjs'),
// some sub-dependencies use a different version of @emotion/react and generate warnings
// in the browser about @emotion/react loaded twice. We want to only load it once
'@emotion/react': require.resolve('@emotion/react'),
// due to our webpack configuration not understanding package.json `exports`
// correctly we must alias this package to the correct file
// the alternative to this alias is to copy-paste the file into our
// source code and miss out in updates
'@locker/near-membrane-dom/custom-devtools-formatter': require.resolve(
'@locker/near-membrane-dom/custom-devtools-formatter.js'
),
},
modules: ['node_modules', path.resolve('public')],
fallback: {
buffer: false,
fs: false,
stream: false,
http: false,
https: false,
string_decoder: false,
},
symlinks: false,
},
ignoreWarnings: [/export .* was not found in/],
stats: {
children: false,
source: false,
},
plugins: [
new webpack.NormalModuleReplacementPlugin(/^@grafana\/schema\/dist\/esm\/(.*)$/, (resource) => {
resource.request = resource.request.replace('@grafana/schema/dist/esm', '@grafana/schema/src');
}),
new CorsWorkerPlugin(),
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
}),
new CopyWebpackPlugin({
patterns: [
{
context: path.join(require.resolve('monaco-editor/package.json'), '../min/vs/'),
from: '**/*',
to: '../lib/monaco/min/vs/', // inside the public/build folder
globOptions: {
ignore: [
'**/*.map', // debug files
],
},
},
{
context: path.join(require.resolve('@kusto/monaco-kusto/package.json'), '../release/min'),
from: '**/*',
to: '../lib/monaco/min/vs/language/kusto/',
},
],
}),
],
module: {
rules: [
{
test: require.resolve('jquery'),
loader: 'expose-loader',
options: {
exposes: ['$', 'jQuery'],
},
},
{
test: /\.html$/,
exclude: /(index|error|index-microfrontend)\-template\.html/,
use: [
{
loader: 'ngtemplate-loader?relativeTo=' + path.resolve(__dirname, '../../public') + '&prefix=public',
},
{
loader: 'html-loader',
options: {
sources: false,
minimize: {
removeComments: false,
collapseWhitespace: false,
},
},
},
],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(svg|ico|jpg|jpeg|png|gif|eot|otf|webp|ttf|woff|woff2|cur|ani|pdf)(\?.*)?$/,
type: 'asset/resource',
generator: { filename: 'static/img/[name].[hash:8][ext]' },
},
// for pre-caching SVGs as part of the JS bundles
{
test: /(unicons|mono|custom)[\\/].*\.svg$/,
type: 'asset/source',
},
],
},
// https://webpack.js.org/plugins/split-chunks-plugin/#split-chunks-example-3
optimization: {
runtimeChunk: 'single',
splitChunks: {
chunks: 'all',
minChunks: 1,
cacheGroups: {
unicons: {
test: /[\\/]node_modules[\\/]@iconscout[\\/]react-unicons[\\/].*[jt]sx?$/,
chunks: 'initial',
priority: 20,
enforce: true,
},
moment: {
test: /[\\/]node_modules[\\/]moment[\\/].*[jt]sx?$/,
chunks: 'initial',
priority: 20,
enforce: true,
},
angular: {
test: /[\\/]node_modules[\\/]angular[\\/].*[jt]sx?$/,
chunks: 'initial',
priority: 50,
enforce: true,
},
defaultVendors: {
test: /[\\/]node_modules[\\/].*[jt]sx?$/,
chunks: 'initial',
priority: -10,
reuseExistingChunk: true,
enforce: true,
},
default: {
priority: -20,
chunks: 'all',
test: /.*[jt]sx?$/,
reuseExistingChunk: true,
},
},
},
},
};