-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.mix.js
118 lines (108 loc) · 3.64 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
const File = require("laravel-mix/src/File");
const mix = require('laravel-mix');
const fs = require("fs")
const path = require("path");
const compress_images = require("compress-images");
const md5 = require("md5");
/**
* Returns a Hash based on the name of the file and the current time.
* Used for production builds only.
*
* @param string
* @returns {*}
*/
function hash(string) {
return md5(string + Date.now().toString(36));
}
mix.setPublicPath("dist/public");
/**
* Extends the webpack config
*/
mix.webpackConfig({
"watchOptions": {
"ignored": ['./node_modules/', "./src/vendor", "./dist/vendor"]
}
})
mix.copyDirectory("src/app", "dist/app");
mix.copyDirectory("src/bin", "dist/bin");
mix.copyDirectory("src/bootstrap", "dist/bootstrap");
mix.copyDirectory("src/public", "dist/public");
mix.copyDirectory("src/routes", "dist/routes");
mix.copyDirectory("src/translations", "dist/translations");
mix.copyDirectory("src/database", "dist/database");
mix.copyDirectory("src/var", "dist/var");
mix.copyDirectory("src/upload", "dist/upload");
mix.copyDirectory("src/resources/vendor", "dist/public/assets/vendor");
mix.copyDirectory("src/resources/fonts", "dist/public/assets/fonts");
mix.copyDirectory("src/resources/media/*", "dist/public/assets/media/")
/**
* BrowserSync config
*/
mix.browserSync({
proxy: "localhost",
files: [
"dist/(app|bin|bootstrap|public|resources|routes|translations|upload|var|views)/**/*"
],
})
/**
* Load all JS files in the /resources/js directory.
* ! NOT RECRUSIVE, just the files directly in the directory.
*/
let js_path = "src/resources/js/";
let js_files = fs.readdirSync(js_path);
if (js_files.length > 0) {
js_files.forEach(function (filename) {
if (!fs.statSync(js_path + filename).isDirectory()) {
if(mix.inProduction()) {
let filename_new = path.basename(filename, ".js");
mix.js(js_path + filename, "dist/public/assets/js/" + filename_new + "." + hash(filename) + ".min.js").vue();
}
else {
mix.js(js_path + filename, "dist/public/assets/js/").vue();
}
}
});
}
/**
* Load all SASS files in the /resources/js directory
* ! NOT RECRUSIVE, just the files directly in the directory.
*/
let sass_path = "src/resources/sass/";
let sass_files = fs.readdirSync(sass_path);
if (sass_files.length > 0) {
sass_files.forEach(function (filename) {
if (!fs.statSync(sass_path + filename).isDirectory()) {
if(mix.inProduction()) {
let filename_new = path.basename(filename, ".sass");
mix.sass(sass_path + filename, "dist/public/assets/css/" + filename_new + "." + hash(filename) + ".min.css");
}
else {
mix.sass(sass_path + filename, "dist/public/assets/css/");
}
}
});
}
/**
* Image compression
*/
if (mix.inProduction()) {
compress_images(
"src/resources/media/img/**/*.{jpg,JPG,jpeg,JPEG,png,svg,gif}",
"dist/public/assets/img/",
{ compress_force: false, statistic: true, autoupdate: true },
false,
{ jpg: { engine: "mozjpeg", command: ["-quality", "60"] } },
{ png: { engine: "pngquant", command: ["--quality=20-50", "-o"] } },
{ svg: { engine: "svgo", command: "--multipass" } },
{ gif: { engine: "gifsicle", command: ['--colors', '64', '--use-col=web', '--scale', ' 0.8'] } },
function (err, completed) {}
);
} else {
mix.copyDirectory("src/resources/media/img/", "dist/public/assets/img/")
}
/**
* Twig minifier
*/
if (!mix.inProduction()) {
mix.copyDirectory("src/views", "dist/views");
}