-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.mix.js
182 lines (154 loc) · 4.5 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
177
178
179
180
181
182
// webpack.mix.js
// Grabs the package.json file to use our site’s environment/values
const pkg = require("./package.json");
let mix = require('laravel-mix');
const baseUrl = 'https://craft-starter.ddev.site';
const homedir = require('os').homedir();
const moment = require("moment");
// Laravel Mix plugins for additional capabilities
// require("laravel-mix-purgecss");
require("laravel-mix-criticalcss");
require("laravel-mix-banner");
// CSS Plugins
//const tailwindJit = require("@tailwindcss/jit");
const tailwindcss = require("tailwindcss");
const autoprefixer = require("autoprefixer");
const presetenv = require("postcss-preset-env");
const hexrgba = require('postcss-hexrgba');
// Image plugins for compression from src folder
const ImageminPlugin = require("imagemin-webpack-plugin").default;
const CopyWebpackPlugin = require("copy-webpack-plugin");
const imageminMozjpeg = require("imagemin-mozjpeg");
mix.setPublicPath('./public/assets/')
.postCss(pkg.paths.src.css + "app.css", "css")
.options({
postCss: [
tailwindcss,
],
autoprefixer: {
options: {
browsers: [
'last 4 versions',
]
}
},
processCssUrls: false,
hmrOptions: {
host: baseUrl,
port: 8080
},
devtool: 'eval-cheap-module-source-map'
})
// Source maps disabled (temporarily?) to improve build time
.sourceMaps()
// combine all our js scripts here
// when npm run production is run will minimize as well
.js(
[
'./node_modules/swiper/swiper-bundle.min.js',
// Alpine plugins before alpine
'./node_modules/@alpinejs/persist/dist/cdn.min.js',
'./node_modules/@alpinejs/collapse/dist/cdn.min.js',
'./node_modules/@alpinejs/focus/dist/cdn.min.js',
'./node_modules/@alpinejs/intersect/dist/cdn.min.js',
// Alpine Js
'./node_modules/alpinejs/dist/cdn.min.js',
// this should go last
'./src/js/app.js'
],
'public/assets/js/scripts.combined.js')
// combine all our vendor css files here
.combine(
[
'./node_modules/plyr/dist/plyr.css',
'./node_modules/swiper/swiper-bundle.min.css'
],
'public/assets/css/vendor.combined.css')
// for some reason plyr doesn't work when concatenated
// so we'll copy to assets and add a script tag to
// layout.html
.copy('node_modules/plyr/dist/plyr.min.js', 'public/assets/js/plyr.min.js')
.banner({
banner: (function () {
return [
'/**!',
' * @project Caffeine Creations Website',
' * @author Sean Smith, Caffeine Creations <[email protected]>',
' * @Copyright Copyright (c) ' + moment().format("YYYY") + ', Caffeine Creations',
' *',
' */',
'',
].join('\n');
})(),
raw: true,
})
.version()
.browserSync({
proxy: baseUrl,
ghostMode: false,
notify: {
styles: {
top: 'auto',
bottom: '1rem'
}
},
https:true,
/*
? SSL-enabled for DDev. You have to copy the SSL cert to somewhere outside of Docker first. Run this at your project root:
docker cp ddev-router:/etc/nginx/certs ~/tmp/DOMAIN-WITH-EXTENSION
(From: https://stackoverflow.com/questions/59730898/cant-connect-browsersync-with-ddev-nginx-server-because-ssl-error):
*/
https: {
key: homedir + "/tmp/certs" + "/master.key",
cert: homedir + "/tmp/certs" + "/master.crt"
},
files: ["src/css/*.css","src/js/*.js","templates/*.twig", "templates/**/*.twig", "templates/*.js", "templates/**/*.js"]
});
mix.disableSuccessNotifications();
// production
if (mix.inProduction()) {
mix.webpackConfig({
plugins: [
//Compress images
new CopyWebpackPlugin([{
from: "./src/img",
to: "./images",
}]),
new ImageminPlugin({
test: /\.(jpe?g|png|gif|svg)$/i,
pngquant: {
quality: "65-80"
},
plugins: [
imageminMozjpeg({
quality: 65,
//Set the maximum memory to use in kbytes
maxMemory: 1000 * 2048
})
]
}),
],
})
.criticalCss({
enabled: mix.inProduction(),
paths: {
base: baseUrl,
templates: './templates/criticalCss/'
},
urls: [
{
url: '/',
template: 'index'
}
],
options: {
minify: true,
width: 1300,
height: 900,
},
})
// copy fonts
.copyDirectory(pkg.paths.src.fonts, pkg.paths.dist.fonts)
.version();
}
// end production