forked from roots/sage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.mix.js
98 lines (82 loc) · 1.89 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
const mix = require('laravel-mix');
let fs = require('fs');
let path = require('path');
// Watch for changes/additions/deletions in folders like images.
require('laravel-mix-copy-watched');
/**
*
* Commands:
*
* npx mix watch
*
* npx mix --production
*
*/
/**
* Setup browser sync (comment out if you don't want it)
*
* Proxy must be the same as .env WP_HOME. (.test is the default domain for valet).
*/
mix.browserSync({
proxy: 'http://project-name.test',
});
/**
* Disable the constant system notifications on Windows.
*/
mix.disableNotifications();
/**
* Setup general public/output folder
*/
const publicPath = 'public';
mix.setPublicPath(`./${publicPath}`);
/**
* Setup main scss file to compile.
*/
mix.sass('resources/scss/main.scss', 'css')
.sass('resources/scss/critical.scss', 'css')
.options({
processCssUrls: false,
autoprefixer: {
options: {
grid: true,
},
},
});
/**
*
* This declares that jQuery is loaded externally (using one wordpress natively)
*/
mix.webpackConfig({
externals: {
jquery: 'jQuery',
},
});
mix.autoload({
jquery: ['$', 'window.jQuery'],
});
/**
* Setup JS file to compile
*/
mix.js('resources/js/main.js', 'js');
mix.js('resources/js/templates/front-page.js', 'js');
// Copy images and fonts keeping any subdirectories intact.
mix.copyDirectoryWatched('resources/images', `${publicPath}/images`, {
base: 'images',
}).copyDirectoryWatched('resources/fonts', `${publicPath}/fonts`, {
base: 'fonts',
});
mix.sourceMaps(true, 'source-map').version();
mix.after(() => {
let manifest = JSON.parse(
fs.readFileSync(`./${publicPath}/mix-manifest.json`).toString()
);
let manifest2 = {};
for (let path of Object.keys(manifest)) {
let newPath = path.replace(/^\//, '');
manifest2[newPath] = manifest[path].replace(/^\//, '');
}
fs.writeFileSync(
`./${publicPath}/mix-manifest.json`,
JSON.stringify(manifest2, null, 2)
);
});