-
Notifications
You must be signed in to change notification settings - Fork 6
/
webpack.mix.js
146 lines (131 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
135
136
137
138
139
140
141
142
143
144
145
146
const mix = require('laravel-mix')
const tailwindcss = require('tailwindcss')
const glob = require('glob-all')
const PurgecssPlugin = require('purgecss-webpack-plugin')
/* ==========================================================================
Config
========================================================================== */
const config = {
siteUrl: 'dogpatchdev.test',
proxyUrl: 'https://dogpatchdev.test',
port: 3000,
openOnStart: false,
pathToLocalSSLCert: '',
pathToLocalSSLKey: '',
filesToWatch: [
'./**/*.php',
'./**/*.html',
'src/scss/**/*.scss',
'src/js/**/*.js',
'src/img/*',
'src/js/components/**/*.vue',
'src/tailwind-config.js',
]
}
/* ==========================================================================
Purge CSS Extractors
========================================================================== */
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g) || []
}
}
/* ==========================================================================
Laravel Mix Config
========================================================================== */
mix
// handle JS files
.js('src/js/app.js', 'dist/js/bundle.min.js')
.disableNotifications()
// Sass files and Tailwind CSS Config
.sass('src/scss/app.scss', 'dist/css/bundle.min.css')
.disableNotifications()
.options({
processCssUrls: false,
postCss: [tailwindcss('src/tailwind-config.js')],
autoprefixer: {
options: {
browsers: ['last 10 versions'],
},
},
})
// Move images to dist directory
.copyDirectory('src/img', 'dist/img')
// Move fonts to dist directory
.copyDirectory('src/fonts', 'dist/fonts')
// BrowserSync
.browserSync({
proxy: config.proxyUrl,
host: config.siteUrl,
open: config.openOnStart,
port: config.port,
https: {
key: config.pathToLocalSSLKey,
cert: config.pathToLocalSSLCert
},
files: config.filesToWatch
})
// remove unused CSS from files - only used when running npm run production
if (mix.inProduction()) {
mix.options({
uglify: {
uglifyOptions: {
mangle: true,
compress: {
warnings: false, // Suppress uglification warnings
pure_getters: true,
conditionals: true,
unused: true,
comparisons: true,
sequences: true,
dead_code: true,
evaluate: true,
if_return: true,
join_vars: true,
},
output: {
comments: false,
},
exclude: [/\.min\.js$/gi], // skip pre-minified libs
},
},
})
// Purge CSS config
// more examples can be found at https://gist.github.com/jack-pallot/217a5d172ffa43c8c85df2cb41b80bad
mix.webpackConfig({
plugins: [
new PurgecssPlugin({
paths: glob.sync([
path.join(__dirname, './**/*.php'),
path.join(__dirname, 'src/js/**/*.js'),
path.join(__dirname, 'src/js/components/**/*.vue'),
]),
extractors: [
{
extractor: TailwindExtractor,
extensions: ['html', 'php', 'js', 'vue'],
},
],
whitelist: [
'p',
'h1',
'h2',
'h3',
'h4',
'h5',
'h6',
'hr',
'ol',
'ol li',
'ul',
'ul li',
'em',
'b',
'strong',
'blockquote',
],
whitelistPatterns: [],
}),
],
})
}