Repository navigation
Expand file tree
/
Copy pathwebpack.config.mjs
More file actions
119 lines (115 loc) · 2.48 KB
/
Copy pathwebpack.config.mjs
File metadata and controls
119 lines (115 loc) · 2.48 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
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
import { execSync } from 'child_process';
import { join } from 'path';
import CircularDependencyPlugin from 'circular-dependency-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import webpack from 'webpack';
const gitCommitSHA = () => {
try {
return execSync('git rev-parse HEAD').toString().trim();
} catch (_) {
return;
}
};
const { DefinePlugin } = webpack;
/**
* @type {import('webpack').Configuration}
*/
const config = {
entry: {
'commercial-standalone': join(
import.meta.dirname,
'src',
'commercial.ts',
),
},
output: {
path: join(import.meta.dirname, 'dist', 'bundle'),
clean: true,
},
resolve: {
modules: [
join(import.meta.dirname, 'src'),
'node_modules', // default location, but we're overiding above, so it needs to be explicit
],
alias: {
svgs: join(import.meta.dirname, 'static', 'svg'),
lodash: 'lodash-es',
'@guardian/commercial-core': join(
import.meta.dirname,
'..',
'core',
'src',
),
// // prebid alias
'prebid.js/dist': join(
import.meta.dirname,
'node_modules',
'prebid.js',
'dist',
'src',
),
},
extensions: ['.js', '.ts', '.tsx', '.jsx'],
},
module: {
rules: [
{
test: /\.[jt]sx?|mjs$/,
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
options: {
transpileOnly: true,
configFile: join(
import.meta.dirname,
'tsconfig.json',
),
},
},
],
},
{
test: /\.svg$/,
exclude: /(node_modules)/,
loader: 'raw-loader',
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: join(
import.meta.dirname,
'static',
'tpc-test-iframe',
'v2',
'index.html',
),
filename: `commercial/tpc-test/v2/index.html`,
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
minifyJS: true,
},
inject: false,
}),
new DefinePlugin({
'process.env.COMMIT_SHA': JSON.stringify(gitCommitSHA()),
'process.env.SDC_URL': JSON.stringify(process.env.SDC_URL),
}),
// eslint-disable-next-line @typescript-eslint/no-unsafe-call -- circular-dependency-plugin is not typed
new CircularDependencyPlugin({
// exclude detection of files based on a RegExp
exclude: /node_modules/,
// add errors to webpack instead of warnings
failOnError: true,
}),
],
};
export default config;