-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.mix.js
96 lines (78 loc) · 2.73 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
const mix = require('laravel-mix');
const path = require("path");
const fs = require("fs");
const { exec } = require('child_process');
const chokidar = require('chokidar');
mix.version();
mix.before(() => {
console.log("Generating aliases based on modules...");
const alias = require("./webpack.alias");
let componentResolverFile = "module.exports = name => {";
for (let moduleName in alias) {
componentResolverFile += "if (name.startsWith(`" + moduleName + "::`)) {"
componentResolverFile += "const [_, component] = name.split(\"::\", 2);"
// componentResolverFile += "return require(`@Domain/" + moduleName + "/Pages/${component}`).default;"
componentResolverFile += "return import(`@Domain/" + moduleName + "/Pages/${component}`).then(m=>m.default);"
componentResolverFile += "}"
}
componentResolverFile += "return require(`@/Pages/${name}`).default";
componentResolverFile += "}";
fs.writeFileSync(path.resolve("resources", "js", "componentResolver.js"), componentResolverFile);
});
mix.extend("dto", new class {
boot() {
const command = () => exec(
`php artisan typescript:transform`,
(error, stdout, stderr) => console.log(stdout)
);
command();
if (Mix.isWatching()) {
(chokidar.watch(["app/DTO/*.php", "app/Domain/**/DTO/*.php"]))
.on('change', (path) => {
console.log(`${path} changed...`);
command();
});
};
}
})
// Generating routes JS file
mix.extend('ziggy', new class {
register(config = {}) {
this.watch = config.watch ?? ['routes/**/*.php'];
this.path = config.path ?? '';
this.enabled = config.enabled ?? !Mix.inProduction();
}
boot() {
if (!this.enabled) return;
const command = () => exec(
`php artisan ziggy:generate ${this.path}`,
(error, stdout, stderr) => console.log(stdout)
);
command();
if (Mix.isWatching() && this.watch) {
(chokidar.watch(this.watch))
.on('change', (path) => {
console.log(`${path} changed...`);
command();
});
};
}
}());
// Javascript
mix.ts('resources/js/app.ts', 'public/js')
.vue({ version: 3 })
.webpackConfig(() => require("./webpack.config"))
.ziggy({
watch: ['routes/**/*.php', 'app/Domain/**/Http/Routes/*.php'],
path: "./resources/js/ziggy.generated.js",
enabled: true,
});
// .webpackConfig({
// resolve: {
// restrictions: [/.+(?<!\.php)$/],
// }
// });
// Styles
mix.postCss('resources/css/app.css', 'public/css', [
require("tailwindcss")
]);