-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwebpack.common.js
More file actions
179 lines (175 loc) · 6.97 KB
/
webpack.common.js
File metadata and controls
179 lines (175 loc) · 6.97 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
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
import path from 'path';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import { fileURLToPath } from 'url';
import webpack from 'webpack';
import fs from 'fs';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const resolvePackage = (pkg) => path.dirname(fileURLToPath(import.meta.resolve(`${pkg}/package.json`)));
export const packageJson = JSON.parse(fs.readFileSync(path.resolve(__dirname, 'package.json'), 'utf-8'));
export default (env, { appVersion }) => {
return {
entry: './src/js/index.js',
cache: {
type: 'filesystem',
buildDependencies: {
config: [fileURLToPath(import.meta.url)],
},
},
module: {
rules: [
{
test: /\.css$/,
include: [
resolvePackage('flag-icon-css')
],
use: [
'style-loader',
{
loader: 'css-loader',
},
],
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
exclude: [
resolvePackage('flag-icon-css')
],
},
{
test: /abaddon1_shard\.png$/,
type: 'asset/resource',
generator: {
filename: 'images/abaddon1_shard.png',
},
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
include: [
resolvePackage('flag-icon-css')
],
exclude: [
/abaddon1_shard\.png$/
],
type: 'asset/resource',
generator: {
filename: 'images/flag-icons/[name].[contenthash:8][ext]',
},
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
exclude: [
resolvePackage('flag-icon-css'),
/abaddon1_shard\.png$/,
resolvePackage('leaflet')
],
type: 'asset/resource',
generator: {
filename: 'images/[name].[contenthash:8][ext]',
},
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
include: [
resolvePackage('leaflet')
],
type: 'asset/resource',
generator: {
filename: 'images/markers/[name][ext]',
emit: false,
},
},
// Markers are copied manually below to ensure the complete set (shadows, @2x) is present.
// The rule above handles path resolution for files explicitly imported or used in CSS.
],
},
plugins: [
new webpack.DefinePlugin({
__APP_VERSION__: JSON.stringify(appVersion),
}),
new HtmlWebpackPlugin({
template: './index.html',
favicon: './src/images/abaddon1_shard.png',
meta: {
viewport: 'width=device-width, initial-scale=1',
'og:description': 'Interactive map of shard data from Ingress events',
'og:title': { property: 'og:title', content: 'Ingress Shards Map' },
}
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.join(resolvePackage('leaflet'), 'dist', 'images'),
to: 'images/markers',
},
{
from: path.resolve(__dirname, 'conf/event_blueprints.json'),
to: 'public/conf/',
transform(content) {
const blueprints = JSON.parse(content.toString());
blueprints.version = appVersion;
return JSON.stringify(blueprints, null, 2);
},
},
{
from: path.resolve(__dirname, 'conf/series_metadata.json'),
to: 'public/conf/',
transform(content) {
const metadata = JSON.parse(content.toString());
metadata.version = appVersion;
return JSON.stringify(metadata, null, 2);
},
},
{
from: path.resolve(__dirname, 'gen/series_geocode.json'),
to: 'public/conf/',
transform(content) {
const geocode = JSON.parse(content.toString());
geocode.version = appVersion;
return JSON.stringify(geocode, null, 2);
},
},
{
from: path.resolve(__dirname, 'docs/assets/shard-site.png'),
to: 'images/',
},
{
from: path.resolve(__dirname, 'src/images/ornament-icons'),
to: 'images/ornament-icons',
},
]
}),
{
apply: (compiler) => {
compiler.hooks.thisCompilation.tap('GenerateVersionFile', (compilation) => {
compilation.hooks.processAssets.tap(
{
name: 'GenerateVersionFile',
stage: webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONAL,
},
(assets) => {
const content = JSON.stringify({ version: appVersion }, null, 2);
assets['public/conf/version.json'] = new webpack.sources.RawSource(content);
}
);
});
}
}
],
resolve: {
alias: {
'leaflet.motion': fileURLToPath(import.meta.resolve('leaflet.motion/dist/leaflet.motion.min.js')),
}
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].bundle.js',
chunkFilename: 'js/[name].[contenthash:8].js',
assetModuleFilename: 'images/[hash][ext][query]',
clean: true,
publicPath: '/',
}
};
};