forked from firefox-devtools/profiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
115 lines (112 loc) · 3.18 KB
/
webpack.config.js
File metadata and controls
115 lines (112 loc) · 3.18 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
const path = require('path');
const webpack = require('webpack');
const fs = require('fs');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CircularDependencyPlugin = require('circular-dependency-plugin');
const includes = [path.join(__dirname, 'src'), path.join(__dirname, 'res')];
// If L10N env variable is set, we read all the locale directories and use
// whatever we have there. This is done to make the l10n branch work with staging
// locales, so localizers can see the result of their translations immediately.
const availableStagingLocales = process.env.L10N
? JSON.stringify(fs.readdirSync('./locales'))
: JSON.stringify(undefined);
const config = {
output: {
filename: '[name].[contenthash].bundle.js',
publicPath: '/',
},
mode: process.env.NODE_ENV,
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx'],
alias: {
// Note: the alias for firefox-profiler is defined at the Babel level, so
// that Jest can profit from it too.
'firefox-profiler-res': path.resolve(__dirname, 'res'),
},
fallback: { zlib: false },
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.(js|ts|tsx)$/,
use: ['babel-loader'],
include: includes,
},
{
test: /\.worker\.js$/,
use: ['file-loader'],
include: includes,
},
{
test: /\.json$/,
use: ['json-loader'],
include: includes,
},
{
test: /\.css?$/,
use: [
'style-loader',
{ loader: 'css-loader', options: { importLoaders: 1 } },
'postcss-loader',
],
include: [
...includes,
path.join(__dirname, 'node_modules', 'photon-colors'),
path.join(__dirname, 'node_modules', 'react-splitter-layout'),
path.join(__dirname, 'node_modules', 'iongraph-web'),
],
},
{
test: /\.jpg$/,
type: 'asset/resource',
},
{
test: /\.png$/,
type: 'asset/resource',
},
{
test: /\.svg$/,
type: 'asset/resource',
},
],
},
plugins: [
new CircularDependencyPlugin({
// exclude node_modules
exclude: /node_modules/,
// add errors to webpack instead of warnings
failOnError: true,
// set the current working directory for displaying module paths
cwd: process.cwd(),
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': `"${process.env.NODE_ENV}"`,
}),
new webpack.DefinePlugin({
AVAILABLE_STAGING_LOCALES: availableStagingLocales,
}),
new HtmlWebpackPlugin({
title: 'Firefox Profiler',
template: 'res/index.html',
favicon: 'res/img/favicon.png',
}),
new CopyWebpackPlugin({
patterns: [
'res/_headers',
'res/_redirects',
'res/contribute.json',
'res/robots.txt',
'res/service-worker-compat.js',
{ from: 'docs-user', to: 'docs' },
{ from: 'locales', to: 'locales' },
],
}),
],
experiments: {
// Make WebAssembly work just like in webpack v4
syncWebAssembly: true,
},
};
module.exports = config;