aboutsummaryrefslogtreecommitdiffhomepage
path: root/webpack.mix.js
blob: 6c4c45fcbc41bce26b0067ae3d90f2c5aacf6598 (plain) (blame)
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
let mix = require('laravel-mix');
let SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel application. By default, we are compiling the Sass
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/assets/js/app.js', 'public/js')
    .js('resources/assets/js/admin.js', 'public/js')
    .js('resources/assets/js/initial_key_gen.js', 'public/js')
    // .ts('resources/assets/js/typescript.ts', 'public/js') => use of typescript!
    .sass('resources/assets/sass/admin.scss', 'public/css')
    .sass('resources/assets/sass/app.scss', 'public/css')
    .sourceMaps()
    .browserSync({
        files: [
            'public/css/*.css',
            'public/js/*.js',
            //'**/*.blade.php'
        ],
        notify: false,
        injectChanges: true,
        proxy: {
            target: '127.0.0.1:8000',
            reqHeaders: function () {
                return {
                    host: 'localhost:3000'
                };
            }
        }
    })
    .disableNotifications()
    .webpackConfig({
        module: {
            rules: [{
                loader: 'postcss-loader',
                options: {
                    plugins: () => [require('autoprefixer')]
                }
            }]
        },
        plugins: [
            new SWPrecacheWebpackPlugin({
                cacheId: 'BEAM-Messenger',
                filename: 'service-worker.js',
                staticFileGlobs: [
                    'public/**/*.{css,js,eot,svg,ttf,woff,woff2,html}', // all compiled/public scripts
                ],
                minify: true,
                stripPrefix: 'public/',
                handleFetch: true,
                maximumFileSizeToCacheInBytes: 20971520,
                // dynamicUrlToDependencies: {
                //     '/': ['resources/views/writeMessage.blade.php'],
                //     '/profile': ['resources/views/profile.blade.php'],
                //     // TODO: add more for even better caching => ??
                // },
                staticFileGlobsIgnorePatterns: [/\.map$/, /mix-manifest\.json$/, /manifest\.json$/],
                navigateFallback: '/',
                importScripts: ['js/service-worker-ext.js'],
                runtimeCaching: [{
                        urlPattern: /^https:\/\/fonts\.googleapis\.com\//,
                        handler: 'cacheFirst'
                    },
                    {
                        urlPattern: /^https:\/\/fonts\.gstatic\.com\//,
                        handler: 'cacheFirst'
                    },
                    {
                        urlPattern: /^https:\/\/cdn\.socket\.io\//,
                        handler: 'cacheFirst'
                    },
                    {
                        urlPattern: /\/socket.io\//,
                        handler: 'cacheFirst'
                    },
                    {
                        urlPattern: /\/_debugbar\//,
                        handler: 'cacheFirst'
                    },
                    {
                        urlPattern: /\/browser-sync\//,
                        handler: 'cacheFirst'
                    },
                    {
                        urlPattern: /\/avatar\//,
                        handler: 'cacheFirst'
                    }
                ],
            })
        ]
    });