Issues (257)

webpack.config.js (1 issue)

Languages
Severity
1
/*
2
 * This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony)
3
 *
4
 * Copyright (C) 2019 - 2023 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
24
const zlib = require('zlib');
0 ignored issues
show
The constant zlib seems to be never used. Consider removing it.
Loading history...
25
const CompressionPlugin = require("compression-webpack-plugin");
26
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
27
const CKEditorWebpackPlugin = require( '@ckeditor/ckeditor5-dev-webpack-plugin' );
28
const { styles } = require( '@ckeditor/ckeditor5-dev-utils' );
29
30
// Manually configure the runtime environment if not already configured yet by the "encore" command.
31
// It's useful when you use tools that rely on webpack.config.js file.
32
if (!Encore.isRuntimeEnvironmentConfigured()) {
33
    Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
34
}
35
36
Encore
37
    // directory where compiled assets will be stored
38
    .setOutputPath('public/build/')
39
    // public path used by the web server to access the output path
40
    .setPublicPath('/build')
41
    // only needed for CDN's or subdirectory deploy
42
    //.setManifestKeyPrefix('build/')
43
44
    /**
45
     * If you are putting Part-DB into a sub directory you have to uncomment these lines and
46
     * replace "part-db/" with your path to Part-DB
47
     */
48
    //.setPublicPath('/part-db/build')
49
    //.setManifestKeyPrefix('build/')
50
51
    /*
52
     * ENTRY CONFIG
53
     *
54
     * Add 1 entry for each "page" of your app
55
     * (including one that's included on every page - e.g. "app")
56
     *
57
     * Each entry will result in one JavaScript file (e.g. app.js)
58
     * and one CSS file (e.g. app.css) if you JavaScript imports CSS.
59
     */
60
    .addEntry('app', './assets/js/app.js')
61
    .addEntry('webauthn_tfa', './assets/js/webauthn_tfa.js')
62
63
64
65
66
    // enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
67
    .enableStimulusBridge('./assets/controllers.json')
68
    //.addEntry('page1', './assets/js/page1.js')
69
    //.addEntry('page2', './assets/js/page2.js')
70
71
    // When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
72
    .splitEntryChunks()
73
74
    // will require an extra script tag for runtime.js
75
    // but, you probably want this, unless you're building a single-page app
76
    .enableSingleRuntimeChunk()
77
78
    /*
79
     * FEATURE CONFIG
80
     *
81
     * Enable & configure other features below. For a full
82
     * list of features, see:
83
     * https://symfony.com/doc/current/frontend.html#adding-more-features
84
     */
85
    .cleanupOutputBeforeBuild()
86
    .enableBuildNotifications()
87
    .enableSourceMaps(!Encore.isProduction())
88
    // enables hashed filenames (e.g. app.abc123.css)
89
    //.enableVersioning(Encore.isProduction())
90
    .enableVersioning()
91
92
93
94
    // configure Babel
95
    // .configureBabel((config) => {
96
    //     config.plugins.push('@babel/a-babel-plugin');
97
    // })
98
99
    // enables and configure @babel/preset-env polyfills
100
    .configureBabelPresetEnv((config) => {
101
        config.useBuiltIns = 'usage';
102
        config.corejs = '3.23';
103
    })
104
    // enables Sass/SCSS support
105
    //.enableSassLoader()
106
107
    // uncomment if you use TypeScript
108
    .enableTypeScriptLoader()
109
110
    // uncomment if you use React
111
    //.enableReactPreset()
112
113
    // uncomment to get integrity="..." attributes on your script & link tags
114
    // requires WebpackEncoreBundle 1.4 or higher
115
    .enableIntegrityHashes(Encore.isProduction())
116
117
    // uncomment if you're having problems with a jQuery plugin
118
    .autoProvidejQuery()
119
120
    .addPlugin( new CKEditorWebpackPlugin( {
121
        // See https://ckeditor.com/docs/ckeditor5/latest/features/ui-language.html
122
        language: 'en',
123
        addMainLanguageTranslationsToAllAssets: true,
124
        additionalLanguages: 'all',
125
        outputDirectory: 'ckeditor_translations'
126
    } ) )
127
128
    // Use raw-loader for CKEditor 5 SVG files.
129
    .addRule( {
130
        test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
131
        loader: 'raw-loader'
132
    } )
133
134
    // Configure other image loaders to exclude CKEditor 5 SVG files.
135
    .configureLoaderRule( 'images', loader => {
136
        loader.exclude = /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/;
137
    } )
138
139
    // Configure PostCSS loader.
140
    .addLoader({
141
        test: /ckeditor5-[^/\\]+[/\\]theme[/\\].+\.css$/,
142
        loader: 'postcss-loader',
143
        options: {
144
            postcssOptions: styles.getPostCssConfig( {
145
                themeImporter: {
146
                    themePath: require.resolve( '@ckeditor/ckeditor5-theme-lark' )
147
                },
148
                minify: true
149
            } )
150
        }
151
    } )
152
153
;
154
155
//These are all the themes that are available in bootswatch
156
const AVAILABLE_THEMES = ['bootstrap', 'cerulean', 'cosmo', 'cyborg', 'darkly', 'flatly', 'journal',
157
    'litera', 'lumen', 'lux', 'materia', 'minty', 'morph', 'pulse', 'quartz', 'sandstone', 'simplex', 'sketchy', 'slate', 'solar',
158
    'spacelab', 'superhero', 'united', 'vapor', 'yeti', 'zephyr'];
159
160
for (const theme of AVAILABLE_THEMES) {
161
    Encore.addEntry('theme_' + theme, './assets/themes/'+theme+'.js');
162
}
163
164
165
if (Encore.isProduction()) {
166
    Encore.addPlugin(new CompressionPlugin({
167
        filename: '[path][base].br',
168
        algorithm: 'brotliCompress',
169
        test: /\.(js|css|html|svg)$/,
170
        compressionOptions: {
171
            // zlib’s `level` option matches Brotli’s `BROTLI_PARAM_QUALITY` option.
172
            level: 11,
173
        },
174
        //threshold: 10240,
175
        minRatio: 0.8,
176
        deleteOriginalAssets: false,
177
    }))
178
179
        .addPlugin(new CompressionPlugin({
180
            filename: '[path][base].gz',
181
            algorithm: 'gzip',
182
            test: /\.(js|css|html|svg)$/,
183
            deleteOriginalAssets: false,
184
        }))
185
}
186
187
if (Encore.isDev()) {
188
    //Only uncomment if needed, as this cause problems with Github actions (job does not finish)
189
    Encore.addPlugin(new BundleAnalyzerPlugin());
190
}
191
192
193
module.exports = Encore.getWebpackConfig();
194