forked from rinvex/cortex-classic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.mix.js
176 lines (138 loc) · 4.76 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/**************************
** Import modules **
**************************/
let path = require('path');
let glob = require('glob');
let mix = require('laravel-mix');
let webpack = require('webpack');
let tailwindcss = require('tailwindcss');
require('laravel-mix-purgecss');
let webpackAliases = {markjs: 'mark.js/dist/jquery.mark.js'};
let WebpackShellPluginNext = require('webpack-shell-plugin-next');
let Dependencies = require('laravel-mix/src/Dependencies.js');
let postCssPlugins = [
tailwindcss('./tailwind.config.js'),
require('postcss-nested'),
];
/**************************
** Initialize Variables **
**************************/
// Modules to skip compiling
let dontDiscover = [];
// npm dependencies to be installed
let moduleDependencies = [];
// Extracted vendor libraries
let vendorLibraries = [
//jQuery
'jquery',
'vue',
'axios',
'lodash',
'mark.js',
'tinymce',
'pusher-js',
'turbolinks',
'laravel-echo',
'intl-tel-input',
'vue-template-compiler',
// Mouse interaction
'jquery-mousewheel',
'jquery-slimscroll',
// Bootstrap
'bootstrap-sass',
'bootstrap-notify',
// Pickers
'timepicker',
'datepair.js',
'bootstrap-datepicker',
'bootstrap-colorpicker',
'fontawesome-iconpicker',
'bootstrap-daterangepicker',
'datepair.js/src/jquery.datepair',
// Misc
'moment',
'select2',
'dropzone',
// Theme
'admin-lte',
];
let scanForCssSelectors = [
path.join(__dirname, 'config/*.php'),
path.join(__dirname, 'app/**/*.js'),
path.join(__dirname, 'app/**/*.php'),
path.join(__dirname, 'app/**/*.vue'),
path.join(__dirname, 'resources/**/*.js'),
path.join(__dirname, 'resources/**/*.php'),
path.join(__dirname, 'node_modules/select2/**/*.js'),
path.join(__dirname, 'node_modules/dropzone/**/*.js'),
path.join(__dirname, 'node_modules/admin-lte/dist/**/*.js'),
path.join(__dirname, 'node_modules/datatables.net/**/*.js'),
path.join(__dirname, 'node_modules/bootstrap-notify/**/*.js'),
path.join(__dirname, 'node_modules/bootstrap-daterangepicker/**/*.js'),
];
let safelist = [/select2/, /alert/, /turbolinks/, /iti/, /dt-/, /dataTable/, /text-/, /col-/, /btn-/, /dropdown/, /picker/, /dropzone/, /progress/, /sidebar/, /nav/, /fa-/];
let webpackPlugins = [
// Reduce bundle size by ignoring moment js local files
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
// Add shell command plugin to execute shell commands on building
new WebpackShellPluginNext({
onBuildStart: {scripts: ['php artisan laroute:generate --ansi --no-interaction', 'php artisan lang:js --ansi --no-lib --no-interaction'], blocking: true, parallel: false},
onBuildEnd: {scripts: [], blocking: true, parallel: false},
}),
];
let purgeCssOptions = {
enabled: true,
variables: true,
content: scanForCssSelectors,
extensions: ['html', 'js', 'php', 'vue'],
safelist: safelist,
};
/**************************
** Dynamic modules **
**************************/
glob.sync('app/*/*/resources/js/webpack.mix.js').forEach(function (file) {
let moduleName = file.split('/')[1] + '/' + file.split('/')[2];
// Check if we need to skip this module
if (dontDiscover.includes(moduleName)) {
return;
}
let moduleWebpack = require(path.join(__dirname, file));
moduleDependencies.push(...moduleWebpack.install || []);
scanForCssSelectors.push(...moduleWebpack.scanForCssSelectors || []);
safelist.push(...moduleWebpack.safelist || []);
webpackPlugins.push(...moduleWebpack.webpackPlugins || []);
moduleWebpack.mix.js.forEach(function(dependency) {
mix.js(dependency.input, dependency.output);
});
moduleWebpack.mix.css.forEach(function(dependency) {
mix.sass(dependency.input, dependency.output);
});
moduleWebpack.copy.forEach(function(path) {
mix.copyDirectory(path.from, path.to);
});
});
// Install module dependencies
(new Dependencies()).enqueue(moduleDependencies).install();
/**************************
** Mix Asset Management **
**************************/
mix
.options({
processCssUrls: true,
postCss: postCssPlugins,
})
.webpackConfig({
plugins: webpackPlugins,
resolve: {alias: webpackAliases},
})
.sass('resources/sass/app.scss', 'public/css/app.css')
.sass('resources/sass/vendor.scss', 'public/css/vendor.css')
.sass('resources/sass/datatables.scss', 'public/css/datatables.css')
.js('resources/js/vendor/datatables.js', 'public/js/datatables.js')
.js('resources/js/app.js', 'public/js/app.js')
.extract(vendorLibraries, 'public/js/vendor.js')
.purgeCss(purgeCssOptions)
.version();