-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
161 lines (157 loc) · 4.35 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
160
161
const CopyPlugin = require("copy-webpack-plugin");
const FaviconsWebpackPlugin = require("favicons-webpack-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const WorkboxPlugin = require("workbox-webpack-plugin");
const fs = require("fs");
const package = require("./package.json");
const path = require("path");
const shell = require("shelljs");
const webpack = require("webpack");
function getVersionFromGit() {
const gitTag = shell.exec("git describe --abbrev=0 --tags");
const gitCommit = shell.exec("git rev-parse --short HEAD");
return {
tag: gitTag.trim(),
commit: gitCommit.trim(),
package: package,
};
}
function readSamplesFromFiles() {
const samples = {};
const groups = fs
.readdirSync(path.resolve(__dirname, "assets/audio/samples"))
.filter((e) => e !== ".DS_Store");
groups.forEach((group) => {
samples[group] = fs
.readdirSync(path.resolve(__dirname, `assets/audio/samples/${group}`))
.filter((e) => e !== ".DS_Store")
.map((file) => `${group}/${file}`);
});
console.group("--- SAMPLES ---");
console.log(samples);
console.groupEnd();
return samples;
}
module.exports = (env) => {
console.log(`ENV: ${env.NODE_ENV} / ${env.production}`);
return {
mode: "development",
devServer: {
port: 3333,
host: "0.0.0.0",
useLocalIp: true,
historyApiFallback: true,
},
entry: {
index: path.resolve(__dirname, "src/js/index.js"),
},
output: {
path: path.resolve(__dirname, "build"),
publicPath: "/",
filename: "[name].[fullhash].bundle.js",
chunkFilename: "[name].[fullhash].bundle.js",
},
resolve: {
extensions: [".js"],
alias: {
"@sass": path.resolve(__dirname, "src/sass/"),
"@glsl": path.resolve(__dirname, "src/glsl/"),
"@assets": path.resolve(__dirname, "assets/"),
"@routes": path.resolve(__dirname, "src/js/routes/"),
"@components": path.resolve(__dirname, "src/js/components/"),
"@utils": path.resolve(__dirname, "src/js/utils/"),
},
},
optimization: {
splitChunks: {
chunks: "all",
},
},
module: {
rules: [
{
test: /\.js$/,
loader: "babel-loader",
exclude: /node_modules/,
},
{
test: /\.s[ac]ss$/i,
use: ["style-loader", "css-loader", "sass-loader"],
},
{
test: /\.(woff(2)?|ttf|otf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "fonts/",
},
},
],
},
{
test: /\.mp3$/,
use: [
{
loader: "file-loader",
options: {
name: "[name].[ext]",
outputPath: "assets/audio/",
},
},
],
},
{
test: /\.svg$/,
use: [
{
loader: "babel-loader",
},
{
loader: "react-svg-loader",
options: {
jsx: true, // true outputs JSX tags
},
},
],
},
{
test: /\.(glsl|frag|vert)$/,
use: ["glslify-import-loader", "raw-loader", "glslify-loader"],
exclude: /node_modules/,
},
],
},
plugins: [
new webpack.DefinePlugin({
"process.env.VERSION": JSON.stringify(getVersionFromGit()),
"process.env.SAMPLES": JSON.stringify(readSamplesFromFiles()),
}),
new HtmlWebpackPlugin({
template: __dirname + "/src/html/index.html",
filename: "index.html",
inject: "body",
hash: true,
}),
new FaviconsWebpackPlugin(
path.resolve(`${__dirname}/assets/svg/favicon.svg`)
),
new CopyPlugin({
patterns: [{ from: "assets", to: "assets" }],
}),
// new WorkboxPlugin.GenerateSW({
// swDest: "sw.js",
// clientsClaim: true,
// skipWaiting: true,
// runtimeCaching: [
// {
// urlPattern: new RegExp("http://localhost:3333/*.js"),
// handler: "StaleWhileRevalidate",
// },
// ],
// maximumFileSizeToCacheInBytes: 15000000,
// }),
],
};
};