-
Notifications
You must be signed in to change notification settings - Fork 40
/
webpack.common.js
176 lines (171 loc) · 3.88 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
171
172
173
174
175
176
/* eslint-env node */
const HTMLPlugin = require('html-webpack-plugin')
const CopyPlugin = require('copy-webpack-plugin')
const path = require('path')
const { NormalModuleReplacementPlugin } = require('webpack')
module.exports.default = {
watchOptions: {
// not setting this option resulted in too many files being watched
// TODO we may have a problem with the number of node dependencies here, some not useful now that publicodes is outside this project. Is there a tool to prune dependencies in package.json ?
ignored: /node_modules/,
},
resolveLoader: {
modules: ['node_modules', path.resolve('loaders/')],
},
resolve: {
fallback: {
path: 'path-browserify',
buffer: 'buffer',
},
alias: {
'@': path.resolve(__dirname, 'source/'),
Source: path.resolve(__dirname, 'source/'),
Actions: path.resolve(__dirname, 'source/actions/'),
Components: path.resolve(__dirname, 'source/components/'),
Pages: path.resolve(__dirname, 'source/sites/publicodes/pages/'),
Enquête: path.resolve(__dirname, 'source/sites/publicodes/enquête/'),
Selectors: path.resolve(__dirname, 'source/selectors/'),
Reducers: path.resolve(__dirname, 'source/reducers/'),
Types: path.resolve(__dirname, 'source/types/'),
Images: path.resolve(__dirname, 'source/images/'),
},
extensions: ['.js', '.ts', '.tsx'],
},
entry: {
publicodes: './source/sites/publicodes/entry.js',
iframe: './source/sites/publicodes/iframe.js',
iframeSimulation: './source/sites/publicodes/iframeSimulation.js',
},
output: {
path: path.resolve('./dist/'),
globalObject: 'self',
chunkFilename: '[name].chunk.js',
},
plugins: [
new CopyPlugin({
patterns: [
'./manifest.webmanifest',
'./source/sites/publicodes/sitemap.txt',
'./source/sites/publicodes/robots.txt',
'./4dc3300c431ca82c00785768559ea871.html',
{
from: './source/images',
to: 'images',
},
],
}),
new NormalModuleReplacementPlugin(
/react-easy-emoji/,
'Components/emoji.tsx'
),
],
}
module.exports.styleLoader = (styleLoader) => ({
test: /\.css$/,
use: [
{ loader: styleLoader },
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
},
],
})
module.exports.commonLoaders = (mode = 'production') => {
const babelLoader = {
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
targets: {
esmodules: true,
},
useBuiltIns: 'entry',
corejs: '3',
},
],
],
plugins: [
// ... other plugins
mode === 'development' && require.resolve('react-refresh/babel'),
].filter(Boolean),
},
}
return [
{
test: /node_modules\/vfile\/core\.js/,
use: [
{
loader: 'imports-loader',
options: {
type: 'commonjs',
imports: ['single process/browser process'],
},
},
],
},
{
test: /\.(js|ts|tsx)$/,
use: [babelLoader],
exclude: /node_modules|dist/,
},
{
test: /\.(jpe?g|png|gif)$/i,
type: 'asset/resource',
},
{
test: /\.yaml$/,
use: ['yaml-loader'],
},
{
test: /\.csv$/,
loader: 'csv-loader',
options: {
dynamicTyping: true,
header: true,
skipEmptyLines: true,
},
},
{
test: /\.(ttf|woff2?)$/,
type: 'asset/resource',
},
{
test: /\.svg$/,
loader: '@svgr/webpack',
options: {
replaceAttrValues: { '#4143d6': 'var(--color)' },
},
},
{
test: /\.md$/,
type: 'asset/source',
},
{
test: /\.mdx$/,
use: [
{
loader: '@mdx-js/loader',
},
],
},
]
}
module.exports.HTMLPlugins = ({ injectTrackingScript = false } = {}) => [
new HTMLPlugin({
template: 'index.html',
logo: 'https://nosgestesclimat.fr/images/dessin-nosgestesclimat.png',
chunks: ['publicodes'],
title: 'Nos Gestes Climat',
description: 'Connaissez-vous votre empreinte sur le climat ?',
filename: 'index.html',
injectTrackingScript,
base: '/',
}),
]