-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.mix.js
75 lines (66 loc) · 1.57 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
const fs = require('fs');
const mix = require('laravel-mix');
mix.setPublicPath('dist');
mix.setResourceRoot('../');
const fontsDir = 'assets/fonts';
const stylesDir = 'assets/styles';
const scriptsDir = 'assets/scripts';
const scriptsVendorDir = 'assets/scripts/vendor';
const discover = (dirs, type, excludedDirs = []) => {
let files = [];
dirs.forEach((dir) => {
if (excludedDirs.indexOf(dir) === -1) {
fs.readdirSync(dir).forEach((node) => {
const nodePath = `${dir}/${node}`;
if (fs.statSync(nodePath).isFile()) {
if (
nodePath.endsWith(type) &&
!node.startsWith('.') &&
!node.startsWith('_')
) {
files.push(nodePath);
}
} else {
files = files.concat(discover([nodePath], type));
}
});
}
});
return files;
};
if (fs.existsSync(fontsDir)) {
discover([fontsDir], '.woff2').forEach((file) => {
mix.copy(file, 'dist/fonts');
});
}
if (fs.existsSync(scriptsVendorDir)) {
discover([scriptsVendorDir], '.js').forEach((file) => {
mix.copy(file, 'dist/scripts/vendor');
});
}
discover(['src/blocks', scriptsDir], '.ts').forEach((file) => {
mix.js(file, 'scripts').webpackConfig({
module: {
rules: [
{
test: /\.ts?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.js', '.ts'],
},
});
});
if (fs.existsSync(stylesDir)) {
discover(['assets/styles'], '.css').forEach((file) => {
mix.postCss(file, 'styles', [
require('postcss-import'),
require('postcss-extend'),
require('tailwindcss/nesting'),
require('tailwindcss'),
]);
});
}