-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.mix.js
92 lines (78 loc) · 2.88 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
const mix = require('laravel-mix');
const fs = require('fs');
const MIX_WP_OPTIONS = {
resolve: {
fallback: {
crypto: require.resolve('crypto-browserify'),
stream: require.resolve('stream-browserify'),
http: require.resolve('stream-http'),
https: require.resolve('https-browserify'),
zlib: require.resolve('browserify-zlib'),
path: require.resolve('path-browserify'),
}
}
}
class ResourceConfig {
constructor(type, filesDir, outputDir, excludeFiles = [], minify = false, hasVue = true) {
this.type = type;
/*this.filesDir = filesDir;*/
this.outputDir = outputDir;
this.excludeFiles = excludeFiles || [];
let files = fs.readdirSync(filesDir);
this.excludeFiles.forEach(function (value) {
if (files.includes(value)) {
files.splice(files.indexOf(value), 1)
}
});
files.forEach(function (value, index) {
files[index] = filesDir + value;
});
this.files = files;
this.minify = minify;
this.hasVue = hasVue;
}
}
const JS_CONTROL_CONFIG = new ResourceConfig('js', 'resources/js/front/', 'public/js/control/', ['required', 'components'], true);
const JS_FAQ_ES_CONFIG = new ResourceConfig('js', 'resources/js/faq/es/', 'public/js/faq/es/', ['required', 'components'], true);
const JS_FAQ_EN_CONFIG = new ResourceConfig('js', 'resources/js/faq/en/', 'public/js/faq/en/', ['required', 'components'], true);
const SASS_CONFIG = new ResourceConfig('sass', 'resources/sass/', 'public/css/custom/', ['imported'], false, false);
/*
|--------------------------------------------------------------------------
| 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.
|
*/
/**
*
* @param {ResourceConfig} config
*/
function applyConf(config) {
let toMinifyFiles = [];
config.files.forEach(function (file) {
if (config.hasVue) {
mix.webpackConfig(MIX_WP_OPTIONS)[config.type](file, config.outputDir)
.vue();
} else {
mix[config.type](file, config.outputDir);
}
if (config.minify) {
let fileParts = file.split('/');
let fileName = fileParts.pop();
toMinifyFiles.push(config.outputDir + fileName);
}
});
if (toMinifyFiles.length > 0) {
//mix.minify(toMinifyFiles);
}
}
applyConf(SASS_CONFIG);
applyConf(JS_CONTROL_CONFIG);
applyConf(JS_FAQ_ES_CONFIG);
applyConf(JS_FAQ_EN_CONFIG);
//Copy fonts
mix.copyDirectory('resources/assets/fonts', 'public/fonts');
mix.disableSuccessNotifications();