-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.mix.js
92 lines (80 loc) · 2.39 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
// Imports
let mix = require('laravel-mix');
let tailwindcss = require('tailwindcss');
let postimport = require('postcss-import');
let url = require("postcss-url")
let presetEnv = require('postcss-preset-env');
let fs = require('fs-extra');
let CleanWebpackPlugin = require('clean-webpack-plugin');
require('laravel-mix-purgecss');
// Config
const cfg = {
paths: {
root: '.',
src: './src',
build: './build',
umbraco: '../MyProject.Web'
}
};
// Don't bother raising toast notifications
mix.disableNotifications();
// Additional webpack configuration
mix.webpackConfig({
// Cleanup previous builds
plugins: [
new CleanWebpackPlugin([`${cfg.paths.build}/js`, `${cfg.paths.build}/css`, `${cfg.paths.build}/images`])
],
// Configure chunking for async components
output: {
publicPath: '/',
chunkFilename: 'js/[name].js?cb=[chunkhash]',
}
});
// Process JS files including VUE
mix.js(`${cfg.paths.src}/js/main.js`, `${cfg.paths.build}/js`)
.extract([
'vue'
])
.sourceMaps();
// Process CSS files
mix.postCss(`${cfg.paths.src}/css/main.css`, `${cfg.paths.build}/css`, [
postimport({ root: `${cfg.paths.src}/css/*.css` }),
url({ url: 'rebase' }),
tailwindcss(`${cfg.paths.root}/tailwind.js`),
presetEnv({
stage: 2,
features: {
'nesting-rules': true
},
browsers: 'last 2 versions'
})
])
.purgeCss({
enabled: mix.inProduction(),
folders: [
`${cfg.paths.src}/js/`,
`${cfg.paths.umbraco}/views/`
],
extensions: ['html', 'cshtml', 'js', 'vue']
});
// Copy build files to Umbraco folder
mix.then(() => {
fs.copySync(cfg.paths.build, cfg.paths.umbraco, {
filter(src) {
return !src.match(/(?:mix-manifest|index.html)/gi);
}
});
});
// ================================================
// LARAVEL QUIRKS - DON'T DELETE
// ================================================
// As mix is designed for laravel projects we need
// a couple of workarounds for some small issues:
// 1: setPublicPath is required otherwise the build
// script stalls with message '95% emitting'
// 2: A mix-manifest.json file is generated which
// is used by Laravel, but we don't need it,
// so just delete it
mix.setPublicPath(cfg.paths.build).then(() => {
fs.removeSync(`${cfg.paths.build}/mix-manifest.json`);
});