-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
159 lines (151 loc) · 4.83 KB
/
webpack.config.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
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
const webpack = require('webpack');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const WorkboxPlugin = require('workbox-webpack-plugin');
const RollbarSourceMapPlugin = require('rollbar-sourcemap-webpack-plugin');
const devMode = process.env.NODE_ENV !== 'production';
const situations = ['controle', 'inventaire', 'tri', 'questions', 'securite', 'prevention', 'maintenance', 'livraison', 'objets_trouves', 'bienvenue', 'plan_de_la_ville', 'cafe_de_la_place', 'place_du_marche'];
const entriesSituations = situations.reduce(function (entries, situation) {
entries[`situation_${situation}`] = path.resolve(__dirname, `src/app/situation_${situation}.js`);
return entries;
}, {});
const aliasSituations = situations.reduce(function (alias, situation) {
alias[situation] = path.resolve(__dirname, `src/situations/${situation}/`);
return alias;
}, {});
const templatesSituations = situations.map(function (situation) {
return new HtmlWebpackPlugin({
filename: `${situation}.html`,
template: path.resolve(__dirname, 'src/public/template_index.html'),
chunks: [`situation_${situation}`],
inject: 'head'
});
});
const PUBLIC_PATH = '/jeu/';
let rollbarSourceMapPlugin = [];
if (process.env.JETON_SERVEUR_ROLLBAR) {
rollbarSourceMapPlugin = [new RollbarSourceMapPlugin({
accessToken: process.env.JETON_SERVEUR_ROLLBAR,
version: process.env.SOURCE_VERSION,
publicPath: PUBLIC_PATH
})];
}
module.exports = {
entry: {
index: path.resolve(__dirname, 'src/app/index.js'),
...entriesSituations
},
output: {
path: path.resolve(__dirname, 'public/jeu/'),
filename: 'js/[name]_[contenthash].js',
publicPath: PUBLIC_PATH // public URL of the output directory when referenced in a browser
},
devtool: devMode ? 'eval-cheap-source-map' : 'source-map',
resolve: {
extensions: ['.js', '.vue'],
fallback: { path: require.resolve('path-browserify') },
alias: {
accueil: path.resolve(__dirname, 'src/situations/accueil/'),
commun: path.resolve(__dirname, 'src/situations/commun/'),
src: path.resolve(__dirname, 'src/'),
...aliasSituations
}
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true
}
}
}
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
options: {
plugins: ['@babel/plugin-syntax-dynamic-import', '@babel/plugin-proposal-object-rest-spread'],
presets: [
[
'@babel/env',
{
modules: false,
useBuiltIns: 'entry',
corejs: { version: '3.16', proposals: true }
}
]
]
}
},
{
test: /\.(sa|sc|c)ss$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
'css-loader',
'sass-loader'
]
},
{
test: /\.(png|jpg|mp3|mp4|svg|woff|woff2|ttf|eot)(\?.*$|$)/i,
type: 'asset/resource'
},
{
test: /\.vue$/,
loader: 'vue-loader'
}
]
},
plugins: [
...rollbarSourceMapPlugin,
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, 'src/public/template_index.html'),
chunks: ['index'],
inject: 'head'
}),
...templatesSituations,
new webpack.EnvironmentPlugin({
URL_API: undefined, // valeur par défaut undefined quand la variable est obligatoire
JETON_CLIENT_ROLLBAR: null, // valeur par défaut null quand la variable est facultative
ROLLBAR_ENV: null,
SOURCE_VERSION: undefined,
SOURCE_VERSION_COURTE: devMode ? 'HEAD' : process.env.SOURCE_VERSION.substring(0, 8),
ANNONCE_GENERALE: null,
HOTJAR_ID: null,
MATOMO_ID: null
}),
new FaviconsWebpackPlugin('./src/public/logo.svg'),
new VueLoaderPlugin(),
new WorkboxPlugin.GenerateSW({
// these options encourage the ServiceWorkers to get in there fast
// and not allow any straggling "old" SWs to hang around
clientsClaim: true,
skipWaiting: true,
maximumFileSizeToCacheInBytes: 50000000
}),
new webpack.DefinePlugin({
__VUE_OPTIONS_API__: true,
__VUE_PROD_DEVTOOLS__: false
})
],
devServer: {
contentBase: './src/public',
host: '0.0.0.0',
disableHostCheck: true,
port: 7700
}
};