-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.mix.js
134 lines (115 loc) · 3.54 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
const desire = require('./webpack/desire');
const dependencies = require('./webpack/dependencies');
const blocks = require("./webpack/blocks");
const mix = require('laravel-mix');
const path = require('path');
const merge = require('webpack-merge');
const namespace = require('./package.json').namespace;
const config = merge(
desire(`${__dirname}/resources/config`),
desire(`${__dirname}/resources/config-local`)
);
const resources = path.join(__dirname, 'resources');
require('laravel-mix-copy-watched');
mix.inWatch = () => process.argv.includes('--watch');
mix.inBuild = () => !process.argv.includes('--watch') && !mix.inProduction();
mix.webpackConfig({
devtool: mix.inProduction() ? 'none' : 'inline-source-map',
output: {
jsonpFunction: `${namespace}WebpackJsonpCallback`
}
});
mix.setPublicPath('dist');
mix.disableNotifications();
mix.options({
processCssUrls: false
});
if (!mix.inProduction()) {
mix.sourceMaps(false, 'inline-source-map');
}
mix.browserSync({
proxy: config.devUrl,
files: config.watch,
open: config.open
});
mix.autoload({
jquery: ['$', 'window.jQuery']
});
if (mix.inProduction()) {
mix.version();
mix.copy(`${resources}/assets/fonts/**/*`, 'dist/fonts');
mix.copy(`${resources}/assets/images/**/*`, 'dist/images');
} else if (mix.inBuild()) {
mix.copy(`${resources}/assets/fonts/**/*`, 'dist/fonts');
mix.copy(`${resources}/assets/images/**/*`, 'dist/images');
} else if (mix.inWatch()) {
mix.copyWatched(`${resources}/assets/images/**/*`, 'dist/images');
}
blocks(__dirname).forEach(block => {
const ext = path.parse(block).ext;
const filename = path.parse(block).name;
const dir = path.parse(block).dir;
const blockName = dir.split(path.sep)[3];
switch (ext) {
case '.js':
case '.jsx':
mix.js(block, `dist/blocks/${blockName}/${filename}.js`);
if (mix.inProduction()) {
mix.babel(`dist/blocks/${blockName}/${filename}.js`, `dist/blocks/${blockName}/${filename}.js`);
}
break;
case '.scss':
mix.sass(block, `dist/blocks/${blockName}/${filename}.css`);
break;
}
});
dependencies(config).forEach(dependency => {
const ext = path.parse(dependency).ext;
const filename = path.parse(dependency).name;
const dir = path.parse(dependency).dir;
switch (ext) {
case '.js':
case '.jsx':
mix.js(`${resources}/assets/${dependency}`, `${dir}/${filename}.js`);
if (mix.inProduction()) {
mix.babel(`dist/${dir}/${filename}.js`, `dist/${dir}/${filename}.js`);
}
break;
case '.scss':
mix.sass(`${resources}/assets/${dependency}`, `${dir}/${filename}.css`);
break;
}
});
const blocksFolders = [
...new Set([...blocks(__dirname)].map(block => path.parse(block).dir))
];
blocksFolders.forEach(block => {
const blockStructure = block.split(path.sep);
const blockPath = path.join(
blockStructure[0],
blockStructure[1],
blockStructure[2]
);
const blockName = block.split(path.sep)[2];
if (mix.inBuild() || mix.inProduction()) {
mix.copy(
path.join(blockPath, "assets/images", "**", "*"),
path.join("dist", "blocks", blockName, "images")
);
mix.copy(
path.join(blockPath, "assets/svg", "**", "*"),
path.join("dist", "blocks", blockName, "svg")
);
}
if (mix.inWatch()) {
mix.copyWatched(
path.join(blockPath, "assets/images", "**", "*"),
path.join("dist", "blocks", blockName, "images")
);
mix.copyWatched(
path.join(blockPath, "assets/svg", "**", "*"),
path.join("dist", "blocks", blockName, "svg")
);
}
});
mix.extract();