-
Notifications
You must be signed in to change notification settings - Fork 81
/
webpack.config.js
236 lines (203 loc) · 8.5 KB
/
webpack.config.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
const Encore = require('@symfony/webpack-encore')
const { PurgeCSSPlugin } = require('purgecss-webpack-plugin')
const { BugsnagSourceMapUploaderPlugin } = require('webpack-bugsnag-plugins')
const dotenv = require('dotenv')
const glob = require('glob-all')
const path = require('path')
const webpack = require('webpack')
const noop = require('noop-webpack-plugin')
// Manually configure the runtime environment if not already configured yet by the "encore" command.
// It's useful when you use tools that rely on webpack.config.js file.
if (!Encore.isRuntimeEnvironmentConfigured()) {
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev')
}
Encore
// directory where compiled assets will be stored
.setOutputPath('public/build/')
// public path used by the web server to access the output path
.setPublicPath('/build')
// overwriting the css versioning until the transition to webpack is full done
.configureFilenames({
css: 'css/[name].css', // -[contenthash] to be used once styles are only imported!
js: 'js/[name]-[chunkhash].js',
})
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
.splitEntryChunks()
// will require an extra script tag for runtime.js
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()
.copyFiles([
// Images
{ from: './assets/images', to: '../images/[path][name].[ext]' },
// Favicon
{ from: './assets/images', pattern: /favicon\.ico/, to: '../[name].[ext]' },
// Catblocks
{ from: './assets/catblocks', to: '../catblocks/[path][name].[ext]' },
// Fonts
{ from: './assets/Fonts', to: '/fonts/[path][name].[ext]' },
// Remix graph (deprecated!) - Complete rework needed
{ from: './assets/Legacy', to: '../js/[path][name].[ext]' },
{ from: './node_modules/vis/dist/', to: '../vis/[path][name].[ext]' },
{
from: './node_modules/jquery/dist/',
pattern: /\.js$/,
to: '../js/modules/[path][name].[ext]',
},
{
from: './node_modules/jquery-ui-dist/',
pattern: /\.js$/,
to: '../js/modules/[path][name].[ext]',
},
{
from: './node_modules/jquery-contextmenu/dist/',
pattern: /\.js$/,
to: '../js/modules/[path][name].[ext]',
},
{
from: './node_modules/jquery-contextmenu/dist/',
pattern: /\.js$/,
to: '../js/modules/[path][name].[ext]',
},
{
from: './node_modules/jquery-contextmenu/dist/',
pattern: /\.css$/,
to: '../css/modules/[path][name].[ext]',
},
{
from: './node_modules/animate.css/',
pattern: /\.css$/,
to: '../css/modules/[path][name].[ext]',
},
])
/*
* ENTRY CONFIG
*
* Add 1 entry for each "page" of your app
* (including one that's included on every page - e.g. "app")
*
* Each entry will result in one JavaScript file (e.g. app.js)
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
*/
.addEntry('base_layout', './assets/Layout/Base.js')
.addEntry('layout_language_menu', './assets/Layout/LanguageMenu.js')
.addStyleEntry('layout_multi_column_article', './assets/Layout/MultiColumnArticle.scss')
.addEntry('index_page', './assets/Index/IndexPage.js')
.addEntry('login_page', './assets/Security/LoginPage.js')
.addEntry('registration_page', './assets/Security/RegistrationPage.js')
.addEntry('password_reset_page', './assets/Security/PasswordResetPage.js')
.addEntry('request_to_reset_password_page', './assets/Security/RequestPasswordResetPage.js')
.addEntry('legacy_search_page', './assets/Search/LegacySearchPage.js')
.addEntry('search_page', './assets/Search/SearchPage.js')
.addEntry('project_page', './assets/Project/ProjectPage.js')
.addEntry('project_comments_page', './assets/Project/ProjectCommentsPage.js')
.addEntry('project_code_view', './assets/Project/CodeView.js')
.addStyleEntry('project_legacy_code_view', './assets/Project/LegacyCodeView.scss')
.addEntry('project_code_statistics', './assets/Project/CodeStatistics.js')
.addEntry('user_achievements_page', './assets/User/AchievementsPage.js')
.addEntry('user_notifications_page', './assets/User/NotificationsPage.js')
.addEntry('user_my_profile_page', './assets/User/MyProfilePage.js')
.addEntry('user_profile_page', './assets/User/ProfilePage.js')
.addEntry('media_library_package_detail_page', './assets/MediaLibrary/PackageDetailPage.js')
.addEntry('studio_detail_page', './assets/Studio/StudioDetailPage.js')
.addEntry('studios_page', './assets/Studio/StudiosPage.js')
.addEntry('studio_create_page', './assets/Studio/CreatePage.js')
.addEntry('studio_add_project_page', './assets/Studio/AddProject.js')
.addStyleEntry('twig_bundle_error', './assets/bundles/TwigBundle/Exception/error.scss')
.addEntry('user_follower_overview', './assets/User/FollowerOverview.js')
// Admin interface
.addEntry('admin_standard_layout', './assets/Admin/Layout.js')
.addEntry('admin_user_communication_broadcast_notification', './assets/Admin/UserCommunication/BroadcastNotification.js')
.addEntry('admin_user_communication_send_mail', './assets/Admin/UserCommunication/SendMail.js')
.addEntry('admin_user_communication_maintenance_information_icon_list', './assets/Admin/UserCommunication/MaintenanceInformation/IconList.js')
.addEntry('admin_system_management_logs', './assets/Admin/SystemManagement/Logs.js')
.addEntry('admin_system_management_maintain', './assets/Admin/SystemManagement/Maintain.js')
.addStyleEntry('admin_system_management_db_updater_achievements', './assets/User/Achievements.scss')
.addEntry('admin_statistics_machine_translation', './assets/Admin/Statistics/MachineTranslation.js')
// Themes
.addStyleEntry('pocketcode', './assets/Theme/pocketcode.scss')
.addStyleEntry('arduino', './assets/Theme/arduino.scss')
.addStyleEntry('create@school', './assets/Theme/[email protected]')
.addStyleEntry('embroidery', './assets/Theme/embroidery.scss')
.addStyleEntry('luna', './assets/Theme/luna.scss')
.addStyleEntry('phirocode', './assets/Theme/phirocode.scss')
.addStyleEntry('pocketalice', './assets/Theme/pocketalice.scss')
.addStyleEntry('pocketgalaxy', './assets/Theme/pocketgalaxy.scss')
.addStyleEntry('mindstorms', './assets/Theme/mindstorms.scss')
// enables the Symfony UX Stimulus bridge (used in assets/js/bootstrap.js)
.enableStimulusBridge('./assets/controllers.json')
/*
* FEATURE CONFIG
*
* Enable & configure other features below. For a full
* list of features, see:
* https://symfony.com/doc/current/frontend.html#adding-more-features
*/
.cleanupOutputBeforeBuild()
.enableBuildNotifications()
.enableSourceMaps()
// enables hashed filenames (e.g. app.abc123.css)
.enableVersioning(Encore.isProduction())
.configureBabel((config) => {
config.plugins.push('@babel/plugin-proposal-class-properties')
})
// enables @babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage'
config.corejs = 3
})
// enables Sass/SCSS support
.enableSassLoader()
// integrity="..." attributes on your script & link tags
// .enableIntegrityHashes(Encore.isProduction())
// Post CSS processing; E.g. auto vendor prefixing, px to rem, ...
.enablePostCssLoader()
/*
* Plugins
*/
.addPlugin(
new PurgeCSSPlugin({
paths: glob.sync([
path.join(__dirname, 'templates/**/*.html.twig'),
path.join(__dirname, 'assets/**/*.js'),
path.join(__dirname, 'assets/**/*.svg'),
]),
content: ['**/*.twig', '**/*.js'],
safelist: {
standard: [/^swal2/, /^modal/, /^mdc/],
},
defaultExtractor: (content) => {
return content.match(/[\w-/:]+(?<!:)/g) || []
},
}),
)
.addPlugin(
(() => {
const log = (result) => {
console.log('Loaded .env vars', result)
return result
}
return new webpack.DefinePlugin(
log(
Encore.isProduction()
? [
dotenv.config({ path: '.env', override: true }),
dotenv.config({ path: '.env.prod', override: true }),
]
: [
dotenv.config({ path: '.env', override: true }),
dotenv.config({ path: '.env.dev', override: true }),
],
),
)
})(),
)
.addPlugin(
process.env.BUGSNAG_API_KEY
? new BugsnagSourceMapUploaderPlugin({
apiKey: process.env.BUGSNAG_API_KEY,
appVersion: process.env.APP_VERSION,
overwrite: true,
})
: noop(),
)
module.exports = Encore.getWebpackConfig()