-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.mix.js
103 lines (92 loc) · 2.67 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
let mix = require('laravel-mix');
const purgecss = require('@fullhuman/postcss-purgecss');
// ? ========== DEVELOPMENT SETTINGS ==========
if(!mix.inProduction()){
mix.setPublicPath('public/build/')
.js("./src/js/main.js", "js")
.sass("./src/scss/main.scss", 'css')
.sourceMaps(true, 'source-map')
// ? This sets up hot module reloading
// ? host 0.0.0.0 enables enables nitro to pick up the devserver
mix.webpackConfig({
// fixes hmr bug introduced in Webpack 5
target: 'web',
output: {
publicPath: "http://127.0.0.1:8081/",
},
devServer:{
public: 'http://127.0.0.1:8081/',
host: '127.0.0.1',
port: 8081,
headers: {
'Access-Control-Allow-Origin': '*'
}
},
});
// ! Optional - disable this chunk if you don't want to run at localhost:3000
// ? This sets up browsersync to refresh the page when html/twig changes
// ? Webpack Dev Server does not listen to html/twig changes because it doesn't process them
mix.browserSync({
// ? Defined in the .env file - sameas default site url
proxy: process.env.DEFAULT_SITE_URL,
watch: true,
watchOptions: {
ignoreInitial: true,
ignored: '*.css'
},
files: ['./templates'],
ignore: "/node_modules/"
});
} else {
// ? ========== PRODUCTION SETTINGS ==========
// ⬇️ Keeps component files in the correct folder.
mix.webpackConfig({
output: {
publicPath: "/assets/dist/",
chunkFilename: "js/components/[name].min.js"
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(bower_components)/,
use: [
{
loader: 'babel-loader',
options: Config.babel()
}
]
}
]
}
});
mix.setPublicPath('public/assets/dist')
.setResourceRoot('/assets/dist')
.js('./src/js/main.js', 'js')
.sass('./src/scss/main.scss', 'css')
.options({
postCss: [
require('postcss-preset-env'),
require('autoprefixer')({
flexbox: true,
grid: "autoplace"
}),
require('cssnano'),
purgecss({
content: ['./templates/**/*.html', './templates/**/*.twig', './src/js/**/*.js'],
safelist: []
})
],
})
.version()
}
// ? Disables system notifications on build
mix.disableNotifications();
// * Helpful Links
// * ===============
// * Laravel Mix Documentation
// * https://laravel-mix.com/docs/5.0/installation
// * Webpack Dev Server Documentation
// * https://webpack.js.org/configuration/dev-server/
// * Browsersync Docs / Options
// * https://www.browsersync.io/docs/options