-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.mix.js
executable file
·194 lines (180 loc) · 5.87 KB
/
webpack.mix.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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const path = require('path')
const mix = require('laravel-mix')
/*
|--------------------------------------------------------------------------
| Mix Asset Management
|--------------------------------------------------------------------------
|
| Mix provides a clean, fluent API for defining some Webpack build steps
| for your Laravel application. By default, we are compiling the Sass
| file for the application as well as bundling up all the JS files.
|
*/
// this plugin is required to automatically load Vuetify components
const VuetifyLoaderPlugin = require('vuetify-loader/lib/plugin')
const { GenerateSW } = require('workbox-webpack-plugin')
const outputPath = function (path, prefix) {
const matches = path.match(/^packages\/([a-z0-9-]+)\/.+\/([a-z0-9-_]+\.[a-z0-9]{3,4})$/i)
return matches !== null && matches.length === 3
? `${prefix}/${matches[1]}/${matches[2]}`
: `${path.replace('resources/', '')}`
}
const output = {
// this causes issues with PWA, some JS files stop loading, needs further investigation
// chunkFilename: 'js/[name].js?id=[chunkhash]'
}
const _module = {
rules: [
// { test: /\.css$/, loader: 'css-loader' },
{
test: /\.(wav|mp3|mp4|webm)$/i,
use: [
{
loader: 'file-loader',
options: {
// it's important to specify [path], so it's passed to outputPath() function
name: '[path][name].[ext]',
// generate custom output path depending on package ID
outputPath: path => outputPath(path, 'audio')
}
}
]
},
{
test: /\.glb$/i,
use: [
{
loader: 'file-loader',
options: {
// it's important to specify [path], so it's passed to outputPath() function
name: '[path][name].[ext]',
// generate custom output path depending on package ID
outputPath: path => outputPath(path, 'models')
}
}
]
},
{
test: /_variables.scss$/,
include: path.resolve(__dirname, 'resources/sass'),
use: [
'vue-style-loader',
'css-loader',
{
loader: 'sass-loader',
options: {
additionalData: "@import '@/resources/sass/_variables.scss';"
}
}
]
}
]
}
const plugins = [
//
]
const resolve = {
alias: {
'~': path.resolve(__dirname, './resources/js'),
scss: path.resolve(__dirname, './resources/sass'),
packages: path.resolve(__dirname, './packages')
},
extensions: ['.js', '.json', '.vue'],
fallback: {
crypto: require.resolve('crypto-browserify'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
os: false,
stream: require.resolve('stream-browserify')
}
}
const optimization = {
splitChunks: {
minSize: 0,
automaticNameDelimiter: '-',
cacheGroups: {
default: false, // To disable any of the default cache groups, set them to false.
// packages: {
// maxAsyncRequests: 1,
// test: (module, chunks) => module.resource && module.resource.match(/\\packages\\[a-z0-9-]+\\resources\\.+\.vue$/),
// name: (module, chunks, cacheGroupKey) => {
// const gameId = module.resource.match(/\\packages\\([a-z0-9-]+)\\resources\\/)[1]
// const [name, ext] = (path.parse(module.resource).base).split('.')
// return `js/packages/${gameId}/${name}`
// }
// },
vueComponents: {
test: module => module.resource && module.resource.match(/[\\/]js[\\/]components[\\/].+\.vue$/),
name: 'components'
},
vueMixins: {
test: module => module.resource && module.resource.match(/[\\/]js[\\/]mixins[\\/].+\.vue$/),
name: 'mixins'
},
vendor: {
test: /[\\/]node_modules[\\/]/,
// cacheGroupKey here is `vendor` as the key of the cacheGroup
name: (module, chunks, cacheGroupKey) => {
// get the module name (folder name in node_modules)
const packageName = module.resource.match(/[\\/]node_modules[\\/](.*?)([\\/]|$)/)[1]
// npm package names are URL-safe, but some servers don't like @ symbols, so strip it
return `vendor/${packageName.replace('@', '')}`
}
}
}
}
}
if (mix.inProduction()) {
// Note that PWA only works with HTTPS
// https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-webpack-plugin.GenerateSW
plugins.push(
new GenerateSW({
cacheId: 'stake-pwa',
sourcemap: false,
mode: 'production',
clientsClaim: true,
skipWaiting: true,
// Do not precache images, audio, text
exclude: [/\.(?:png|jpg|jpeg|svg|wav|mp3|webm|eot|ttf|woff|woff2|txt|map|glb)$/, /js\/packages\/.+\.js$/],
// Define runtime caching rules.
runtimeCaching: [
{
urlPattern: /^https:\/\/fonts\.(?:googleapis|gstatic)\.com\//,
handler: 'NetworkFirst'
},
{
urlPattern: /\.(?:png|jpg|jpeg|svg|wav|mp3|webm|eot|ttf|woff|woff2)$/,
handler: 'CacheFirst',
options: {
cacheName: 'assets',
expiration: {
maxEntries: 50
}
}
}
]
}))
}
// https://stackoverflow.com/a/63255974/2767324
mix.extend('vuetify', new class {
webpackConfig (config) {
config.plugins.push(new VuetifyLoaderPlugin())
}
})
mix.webpackConfig({ output, module: _module, plugins, resolve, optimization })
mix.options({
terser: {
extractComments: false,
terserOptions: {
output: {
comments: false
}
}
}
})
mix
.js('resources/js/app.js', 'public/js')
.vuetify('vuetify-loader')
.vue()
.version()
// .sourceMaps()