Passed
Push — master ( db9257...bd1da1 )
by Jan
05:43
created

webpack.config.js (1 issue)

1
/*
2
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
3
 *
4
 * Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19
 *
20
 */
21
22
var Encore = require('@symfony/webpack-encore');
23
const CopyPlugin = require('copy-webpack-plugin');
24
25
const zlib = require('zlib');
26
const CompressionPlugin = require("compression-webpack-plugin");
27
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
28
29
// Manually configure the runtime environment if not already configured yet by the "encore" command.
30
// It's useful when you use tools that rely on webpack.config.js file.
31
if (!Encore.isRuntimeEnvironmentConfigured()) {
32
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
33
}
34
35
Encore
36
    // directory where compiled assets will be stored
37
    .setOutputPath('public/build/')
38
    // public path used by the web server to access the output path
39
    .setPublicPath('/build')
40
    // only needed for CDN's or sub-directory deploy
41
    //.setManifestKeyPrefix('build/')
42
43
    /**
44
     * If you are putting Part-DB into a sub directory you have to uncomment these lines and
45
     * replace "part-db/" with your path to Part-DB
46
     */
47
    //.setPublicPath('/part-db/build')
48
    //.setManifestKeyPrefix('build/')
49
50
    /*
51
     * ENTRY CONFIG
52
     *
53
     * Add 1 entry for each "page" of your app
54
     * (including one that's included on every page - e.g. "app")
55
     *
56
     * Each entry will result in one JavaScript file (e.g. app.js)
57
     * and one CSS file (e.g. app.css) if you JavaScript imports CSS.
58
     */
59
    .addEntry('app', './assets/js/app.js')
60
61
    .addEntry('ru2ftwofactor', './assets/js/u2f_auth.js')
62
    //.addEntry('ajaxUI', './assets/ts_src/ajax_ui.ts')
63
    //.addEntry('page1', './assets/js/page1.js')
64
    //.addEntry('page2', './assets/js/page2.js')
65
66
    // When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
67
    .splitEntryChunks()
68
69
    // will require an extra script tag for runtime.js
70
    // but, you probably want this, unless you're building a single-page app
71
    .enableSingleRuntimeChunk()
72
73
    /*
74
     * FEATURE CONFIG
75
     *
76
     * Enable & configure other features below. For a full
77
     * list of features, see:
78
     * https://symfony.com/doc/current/frontend.html#adding-more-features
79
     */
80
    .cleanupOutputBeforeBuild()
81
    .enableBuildNotifications()
82
    .enableSourceMaps(!Encore.isProduction())
83
    // enables hashed filenames (e.g. app.abc123.css)
84
    .enableVersioning(Encore.isProduction())
85
86
    // enables @babel/preset-env polyfills
87
    .configureBabelPresetEnv((config) => {
88
        config.useBuiltIns = 'usage';
89
        config.corejs = 3;
90
    })
91
    // enables Sass/SCSS support
92
    //.enableSassLoader()
93
94
    // uncomment if you use TypeScript
95
    .enableTypeScriptLoader()
96
97
    // uncomment if you're having problems with a jQuery plugin
98
    .autoProvidejQuery()
99
100
    .addPlugin(new CopyPlugin([
101
        {
102
            from: 'node_modules/bootswatch/dist/*/*.min.css',
103
            to: 'themes/[2].[ext]',
104
            test: /.*([\/\\])(.+)([\/\\]).*\.css$/
105
        },
106
        {
107
            from: 'node_modules/bootstrap/dist/css/bootstrap.min.css',
108
            to: 'themes/bootstrap.css'
109
        }
110
    ]))
111
112
// uncomment if you use API Platform Admin (composer req api-admin)
113
//.enableReactPreset()
114
//.addEntry('admin', './assets/js/admin.js')
115
;
116
117
if (Encore.isProduction()) {
118
    Encore.addPlugin(new CompressionPlugin({
119
        filename: '[path].br[query]',
120
        algorithm: 'brotliCompress',
121
        test: /\.(js|css|html|svg)$/,
122
        compressionOptions: {
123
            // zlib’s `level` option matches Brotli’s `BROTLI_PARAM_QUALITY` option.
124
            level: 11,
125
        },
126
        //threshold: 10240,
127
        minRatio: 0.8,
128
        deleteOriginalAssets: false,
129
    }))
130
131
        .addPlugin(new CompressionPlugin({
132
            filename: '[path].gz[query]',
133
            algorithm: 'gzip',
134
            test: /\.(js|css|html|svg)$/,
135
            deleteOriginalAssets: false,
136
        }))
137
}
138
139
if (Encore.isDev()) {
0 ignored issues
show
Comprehensibility Documentation Best Practice introduced by
This code block is empty. Consider removing it or adding a comment to explain.
Loading history...
140
    //Only uncomment if needed, as this cause problems with Github actions (job does not finish)
141
    //Encore.addPlugin(new BundleAnalyzerPlugin());
142
}
143
144
145
module.exports = Encore.getWebpackConfig();
146