forked from teamducro/gloomhaven-storyline
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.mix.js
77 lines (70 loc) · 2.58 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
let mix = require('laravel-mix');
const tailwindcss = require('tailwindcss');
const md5File = require('md5-file/promise');
const replace = require('replace-in-file');
const dayjs = require('dayjs');
mix.extend('i18n', new class {
webpackRules() {
return [
{
resourceQuery: /blockType=i18n/,
type: 'javascript/auto',
loader: '@kazupon/vue-i18n-loader',
},
];
}
}(),
);
mix.i18n()
.js('resources/js/app.js', 'js').vue()
.js('resources/js/gtm.js', 'js')
.js('resources/js/website.js', 'js').vue()
.sass('resources/sass/app.scss', 'css')
.sass('resources/sass/website.scss', 'css')
.sass('resources/sass/theme.scss', 'css', {
sassOptions: {
includePaths: ['./node_modules']
}
})
.sass('resources/sass/website-theme.scss', 'css', {
sassOptions: {
includePaths: ['./node_modules']
}
})
.copyDirectory('resources/public', 'public')
.copyDirectory('resources/img', 'public/img')
.copyDirectory('resources/svg', 'public/svg')
.copyDirectory('resources/fonts', 'public/fonts')
.options({
processCssUrls: false,
postCss: [tailwindcss('./tailwind.config.js')],
autoprefixer: {remove: false}
})
.setPublicPath('public')
.override(config => {
config.module.rules.find(rule => rule.test.test('.svg')).exclude = /\.svg$/;
config.module.rules.push({
test: /\.svg$/,
use: [{loader: 'html-loader'}]
});
})
.then(async () => {
await versionFile('public/js/website.js', mix.inProduction());
await versionFile('public/js/app.js', mix.inProduction());
await versionFile('public/js/gtm.js', mix.inProduction());
await versionFile('public/css/app.css', mix.inProduction());
await versionFile('public/css/website.css', mix.inProduction());
await versionFile('public/css/theme.css', mix.inProduction());
// set date in sitemap
for (let i = 0; i < 20; i++) {
await replace({files: 'public/sitemap.xml', from: /release-date/, to: dayjs().format('YYYY-MM-DD')});
}
});
async function versionFile(path, applyVersion) {
const file = path.split('/').pop();
const pattern = new RegExp(file.replace('.', '\\.') + '(\\?v=[a-f0-9]{32})?', 'g');
let to = applyVersion
? file + '?v=' + await md5File(path)
: file;
return replace({files: ['public/index.html', 'public/tracker/index.html'], from: pattern, to: to});
}