forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallencore-install-encore.diff
402 lines (402 loc) · 13.3 KB
/
installencore-install-encore.diff
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
diff --git a/.gitignore b/.gitignore
index a67f91e..7fdcc07 100644
--- a/.gitignore
+++ b/.gitignore
@@ -8,3 +8,10 @@
/var/
/vendor/
###< symfony/framework-bundle ###
+
+###> symfony/webpack-encore-bundle ###
+/node_modules/
+/public/build/
+npm-debug.log
+yarn-error.log
+###< symfony/webpack-encore-bundle ###
diff --git a/assets/app.js b/assets/app.js
new file mode 100644
index 0000000..bb0a6aa
--- /dev/null
+++ b/assets/app.js
@@ -0,0 +1,12 @@
+/*
+ * Welcome to your app's main JavaScript file!
+ *
+ * We recommend including the built version of this JavaScript file
+ * (and its CSS file) in your base layout (base.html.twig).
+ */
+
+// any CSS you import will output into a single css file (app.css in this case)
+import './styles/app.css';
+
+// start the Stimulus application
+import './bootstrap';
diff --git a/assets/bootstrap.js b/assets/bootstrap.js
new file mode 100644
index 0000000..cb771d2
--- /dev/null
+++ b/assets/bootstrap.js
@@ -0,0 +1,8 @@
+import { startStimulusApp } from '@symfony/stimulus-bridge';
+
+// Registers Stimulus controllers from controllers.json and in the controllers/ directory
+export const app = startStimulusApp(require.context(
+ '@symfony/stimulus-bridge/lazy-controller-loader!./controllers',
+ true,
+ /\.(j|t)sx?$/
+));
diff --git a/assets/controllers.json b/assets/controllers.json
new file mode 100644
index 0000000..a1c6e90
--- /dev/null
+++ b/assets/controllers.json
@@ -0,0 +1,4 @@
+{
+ "controllers": [],
+ "entrypoints": []
+}
diff --git a/assets/controllers/hello_controller.js b/assets/controllers/hello_controller.js
new file mode 100644
index 0000000..8c79f65
--- /dev/null
+++ b/assets/controllers/hello_controller.js
@@ -0,0 +1,16 @@
+import { Controller } from 'stimulus';
+
+/*
+ * This is an example Stimulus controller!
+ *
+ * Any element with a data-controller="hello" attribute will cause
+ * this controller to be executed. The name "hello" comes from the filename:
+ * hello_controller.js -> "hello"
+ *
+ * Delete this file or adapt it for your use!
+ */
+export default class extends Controller {
+ connect() {
+ this.element.textContent = 'Hello Stimulus! Edit me in assets/controllers/hello_controller.js';
+ }
+}
diff --git a/assets/styles/app.css b/assets/styles/app.css
new file mode 100644
index 0000000..cb33b13
--- /dev/null
+++ b/assets/styles/app.css
@@ -0,0 +1,3 @@
+body {
+ background-color: lightgray;
+}
diff --git a/composer.json b/composer.json
index 0a3c67b..37745df 100644
--- a/composer.json
+++ b/composer.json
@@ -27,6 +27,7 @@
"symfony/serializer": "5.2.*",
"symfony/twig-bundle": "5.2.*",
"symfony/validator": "5.2.*",
+ "symfony/webpack-encore-bundle": "^1.9",
"symfony/yaml": "5.2.*",
"twig/extra-bundle": "^2.12|^3.0",
"twig/intl-extra": "^3.2",
diff --git a/composer.lock b/composer.lock
index 75afa9d..2c37731 100644
--- a/composer.lock
+++ b/composer.lock
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "c86f2cc6aa9794b35f371a87ed63d1f4",
+ "content-hash": "7b64a7abe26e77d0ad0b3d13e56216e0",
"packages": [
{
"name": "composer/package-versions-deprecated",
@@ -5947,6 +5947,77 @@
],
"time": "2021-01-27T10:01:46+00:00"
},
+ {
+ "name": "symfony/webpack-encore-bundle",
+ "version": "v1.11.1",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/symfony/webpack-encore-bundle.git",
+ "reference": "395b60a549ded8e7f77f0d551815d7555e2d9eb0"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/symfony/webpack-encore-bundle/zipball/395b60a549ded8e7f77f0d551815d7555e2d9eb0",
+ "reference": "395b60a549ded8e7f77f0d551815d7555e2d9eb0",
+ "shasum": ""
+ },
+ "require": {
+ "php": ">=7.1.3",
+ "symfony/asset": "^4.4 || ^5.0",
+ "symfony/config": "^4.4 || ^5.0",
+ "symfony/dependency-injection": "^4.4 || ^5.0",
+ "symfony/http-kernel": "^4.4 || ^5.0",
+ "symfony/service-contracts": "^1.0 || ^2.0"
+ },
+ "require-dev": {
+ "symfony/framework-bundle": "^4.4 || ^5.0",
+ "symfony/phpunit-bridge": "^4.4 || ^5.0",
+ "symfony/twig-bundle": "^4.4 || ^5.0",
+ "symfony/web-link": "^4.4 || ^5.0"
+ },
+ "type": "symfony-bundle",
+ "extra": {
+ "thanks": {
+ "name": "symfony/webpack-encore",
+ "url": "https://github.com/symfony/webpack-encore"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Symfony\\WebpackEncoreBundle\\": "src"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Symfony Community",
+ "homepage": "https://symfony.com/contributors"
+ }
+ ],
+ "description": "Integration with your Symfony app & Webpack Encore!",
+ "support": {
+ "issues": "https://github.com/symfony/webpack-encore-bundle/issues",
+ "source": "https://github.com/symfony/webpack-encore-bundle/tree/v1.11.1"
+ },
+ "funding": [
+ {
+ "url": "https://symfony.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/fabpot",
+ "type": "github"
+ },
+ {
+ "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+ "type": "tidelift"
+ }
+ ],
+ "time": "2021-02-17T13:45:51+00:00"
+ },
{
"name": "symfony/yaml",
"version": "v5.2.3",
diff --git a/config/bundles.php b/config/bundles.php
index 484569d..b0ce84c 100644
--- a/config/bundles.php
+++ b/config/bundles.php
@@ -13,4 +13,5 @@ return [
Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true],
Doctrine\Bundle\FixturesBundle\DoctrineFixturesBundle::class => ['dev' => true, 'test' => true],
+ Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
];
diff --git a/config/packages/assets.yaml b/config/packages/assets.yaml
new file mode 100644
index 0000000..051d36d
--- /dev/null
+++ b/config/packages/assets.yaml
@@ -0,0 +1,3 @@
+framework:
+ assets:
+ json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
diff --git a/config/packages/prod/webpack_encore.yaml b/config/packages/prod/webpack_encore.yaml
new file mode 100644
index 0000000..d0b3ba8
--- /dev/null
+++ b/config/packages/prod/webpack_encore.yaml
@@ -0,0 +1,4 @@
+#webpack_encore:
+ # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
+ # Available in version 1.2
+ #cache: true
diff --git a/config/packages/test/webpack_encore.yaml b/config/packages/test/webpack_encore.yaml
new file mode 100644
index 0000000..02a7651
--- /dev/null
+++ b/config/packages/test/webpack_encore.yaml
@@ -0,0 +1,2 @@
+#webpack_encore:
+# strict_mode: false
diff --git a/config/packages/webpack_encore.yaml b/config/packages/webpack_encore.yaml
new file mode 100644
index 0000000..90f1a1d
--- /dev/null
+++ b/config/packages/webpack_encore.yaml
@@ -0,0 +1,30 @@
+webpack_encore:
+ # The path where Encore is building the assets - i.e. Encore.setOutputPath()
+ output_path: '%kernel.project_dir%/public/build'
+ # If multiple builds are defined (as shown below), you can disable the default build:
+ # output_path: false
+
+ # Set attributes that will be rendered on all script and link tags
+ script_attributes:
+ defer: true
+ # link_attributes:
+
+ # If using Encore.enableIntegrityHashes() and need the crossorigin attribute (default: false, or use 'anonymous' or 'use-credentials')
+ # crossorigin: 'anonymous'
+
+ # Preload all rendered script and link tags automatically via the HTTP/2 Link header
+ # preload: true
+
+ # Throw an exception if the entrypoints.json file is missing or an entry is missing from the data
+ # strict_mode: false
+
+ # If you have multiple builds:
+ # builds:
+ # pass "frontend" as the 3rg arg to the Twig functions
+ # {{ encore_entry_script_tags('entry1', null, 'frontend') }}
+
+ # frontend: '%kernel.project_dir%/public/frontend/build'
+
+ # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
+ # Put in config/packages/prod/webpack_encore.yaml
+ # cache: true
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..ba0e4f4
--- /dev/null
+++ b/package.json
@@ -0,0 +1,18 @@
+{
+ "devDependencies": {
+ "@symfony/stimulus-bridge": "^2.0.0",
+ "@symfony/webpack-encore": "^1.0.0",
+ "core-js": "^3.0.0",
+ "regenerator-runtime": "^0.13.2",
+ "stimulus": "^2.0.0",
+ "webpack-notifier": "^1.6.0"
+ },
+ "license": "UNLICENSED",
+ "private": true,
+ "scripts": {
+ "dev-server": "encore dev-server",
+ "dev": "encore dev",
+ "watch": "encore dev --watch",
+ "build": "encore production --progress"
+ }
+}
diff --git a/symfony.lock b/symfony.lock
index cb203f4..0689685 100644
--- a/symfony.lock
+++ b/symfony.lock
@@ -429,6 +429,28 @@
"config/routes/dev/web_profiler.yaml"
]
},
+ "symfony/webpack-encore-bundle": {
+ "version": "1.9",
+ "recipe": {
+ "repo": "github.com/symfony/recipes",
+ "branch": "master",
+ "version": "1.9",
+ "ref": "579d8de06df2ceb34d39e84e84c0c051b9b5ac68"
+ },
+ "files": [
+ "assets/app.js",
+ "assets/bootstrap.js",
+ "assets/controllers.json",
+ "assets/controllers/hello_controller.js",
+ "assets/styles/app.css",
+ "config/packages/assets.yaml",
+ "config/packages/prod/webpack_encore.yaml",
+ "config/packages/test/webpack_encore.yaml",
+ "config/packages/webpack_encore.yaml",
+ "package.json",
+ "webpack.config.js"
+ ]
+ },
"symfony/yaml": {
"version": "v5.2.1"
},
diff --git a/webpack.config.js b/webpack.config.js
new file mode 100644
index 0000000..056b04a
--- /dev/null
+++ b/webpack.config.js
@@ -0,0 +1,75 @@
+const Encore = require('@symfony/webpack-encore');
+
+// 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')
+ // only needed for CDN's or sub-directory deploy
+ //.setManifestKeyPrefix('build/')
+
+ /*
+ * ENTRY CONFIG
+ *
+ * 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('app', './assets/app.js')
+
+ // enables the Symfony UX Stimulus bridge (used in assets/bootstrap.js)
+ .enableStimulusBridge('./assets/controllers.json')
+
+ // 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()
+
+ /*
+ * 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(!Encore.isProduction())
+ // 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()
+
+ // uncomment if you use TypeScript
+ //.enableTypeScriptLoader()
+
+ // uncomment if you use React
+ //.enableReactPreset()
+
+ // uncomment to get integrity="..." attributes on your script & link tags
+ // requires WebpackEncoreBundle 1.4 or higher
+ //.enableIntegrityHashes(Encore.isProduction())
+
+ // uncomment if you're having problems with a jQuery plugin
+ //.autoProvidejQuery()
+;
+
+module.exports = Encore.getWebpackConfig();