forked from Catrobat/Catroweb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
213 lines (184 loc) · 8.68 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
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([
// Bootstrap (deprecated!)
{ from: './node_modules/bootstrap', to: '../bootstrap/[path][name].[ext]' },
// VIS (used in remix graph) (deprecated!)
// We need the whole dist folder because the css references multiple images
{ from: './node_modules/vis/dist/', to: '../vis/[path][name].[ext]' },
// Fonts (deprecated!)
{ from: './assets/fonts', to: '/fonts/[path][name].[ext]' },
{ from: './node_modules/@fortawesome/', to: '../@fortawesome/[path][name].[ext]' },
{ from: './node_modules/@fortawesome/fontawesome-free/webfonts', to: '../webfonts/[path][name].[ext]' },
{ from: './node_modules/material-icons/', to: '../material-icons/[path][name].[ext]' },
// 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]' },
// JS (deprecated!)
{ from: './assets/js/custom', to: '../js/[path][name].[ext]' },
{ from: './node_modules/clipboard/dist/', pattern: /\.js$/, to: '../js/modules/[path][name].[ext]' },
{ from: './node_modules/bootstrap/dist/js', pattern: /\.js$/, to: '../js/modules/[path][name].[ext]' },
{ from: './node_modules/sweetalert2/dist/', pattern: /\.js$/, to: '../js/modules/[path][name].[ext]' },
{ from: './node_modules/jquery/dist/', pattern: /\.js$/, to: '../js/modules/[path][name].[ext]' },
{ from: './node_modules/textfilljs/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/lazysizes/', pattern: /\.js$/, to: '../js/modules/[path][name].[ext]' },
{ from: './node_modules/jwt-decode/build/', pattern: /\.js$/, to: '../js/modules/[path][name].[ext]' },
// CSS (deprecated!)
{ 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', './assets/js/base.js')
.addEntry('index', './assets/js/index.js')
.addEntry('achievements_overview', './assets/js/achievements_overview.js')
.addEntry('notifications_overview', './assets/js/notifications_overview.js')
.addEntry('follower_overview', './assets/js/follower_overview.js')
.addEntry('my_profile', './assets/js/my_profile.js')
.addEntry('profile', './assets/js/profile.js')
.addEntry('project', './assets/js/project.js')
.addEntry('program_comments', './assets/js/custom/program_comments.js')
.addEntry('search_old', './assets/js/search_old.js')
.addEntry('search', './assets/js/search.js')
.addEntry('media_library', './assets/js/media_library.js')
.addEntry('login', './assets/js/login.js')
.addEntry('register', './assets/js/register.js')
.addEntry('request', './assets/js/request.js')
.addEntry('reset', './assets/js/reset.js')
.addEntry('check_email', './assets/js/check_email.js')
.addEntry('studio_detail', './assets/js/studio_detail.js')
.addEntry('code_view', './assets/js/code_view.js')
// SCSS to CSS
.addStyleEntry('achievements', './assets/styles/components/achievements.scss')
.addStyleEntry('program', './assets/styles/custom/program.scss')
.addStyleEntry('multi_column_article', './assets/styles/custom/multi_column_article.scss')
.addStyleEntry('old_code_view', './assets/styles/custom/old_code_view.scss')
.addStyleEntry('code_statistics', './assets/styles/components/code_statistics.scss')
.addStyleEntry('project_list', './assets/styles/components/project_list.scss')
.addStyleEntry('user_list', './assets/styles/components/user_list.scss')
.addStyleEntry('profile_styles', './assets/styles/custom/profile.scss')
.addStyleEntry('remixgraph', './assets/styles/custom/remixgraph.scss')
.addStyleEntry('error', './assets/styles/error.scss')
// Themes
.addStyleEntry('pocketcode', './assets/styles/themes/pocketcode.scss')
.addStyleEntry('arduino', './assets/styles/themes/arduino.scss')
.addStyleEntry('create@school', './assets/styles/themes/create@school.scss')
.addStyleEntry('embroidery', './assets/styles/themes/embroidery.scss')
.addStyleEntry('luna', './assets/styles/themes/luna.scss')
.addStyleEntry('phirocode', './assets/styles/themes/phirocode.scss')
.addStyleEntry('pocketalice', './assets/styles/themes/pocketalice.scss')
.addStyleEntry('pocketgalaxy', './assets/styles/themes/pocketgalaxy.scss')
.addStyleEntry('mindstorms', './assets/styles/themes/mindstorms.scss')
// enables the Symfony UX Stimulus bridge (used in assets/js/bootstrap.js)
.enableStimulusBridge('./assets/js/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())
// uncomment if you're having problems with a jQuery plugin
.autoProvidejQuery()
// 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()