Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit 0804cfc

Browse files
committed
Remplace custom Webpack config with Encore
1 parent 63ae847 commit 0804cfc

15 files changed

Lines changed: 1001 additions & 151 deletions

File tree

generators/symfony/templates/base-twig/.babelrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

generators/symfony/templates/base-twig/.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/.php-cs-fixer.cache
33
/node_modules/
44
/phpunit.xml
5-
/public/assets/
5+
/public/build/
66
/public/bundles/
77
/var/
88
/vendor/

generators/symfony/templates/base-twig/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
"symfony/twig-bundle": "^6.4.13",
2727
"symfony/validator": "^6.4.17",
2828
"symfony/web-link": "^6.4.13",
29+
"symfony/webpack-encore-bundle": "^2.2.0",
2930
"symfony/yaml": "^6.4.13"
3031
},
3132
"require-dev": {

generators/symfony/templates/base-twig/composer.lock

Lines changed: 73 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

generators/symfony/templates/base-twig/config/bundles.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,5 @@
1111
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
1212
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true, 'test' => true],
1313
Sentry\SentryBundle\SentryBundle::class => ['all' => true],
14+
Symfony\WebpackEncoreBundle\WebpackEncoreBundle::class => ['all' => true],
1415
];

generators/symfony/templates/base-twig/config/packages/assets.yaml

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
webpack_encore:
2+
# The path where Encore is building the assets - i.e. Encore.setOutputPath()
3+
output_path: '%kernel.project_dir%/public/build'
4+
# If multiple builds are defined (as shown below), you can disable the default build:
5+
# output_path: false
6+
7+
# Set attributes that will be rendered on all script and link tags
8+
script_attributes:
9+
defer: true
10+
# Uncomment (also under link_attributes) if using Turbo Drive
11+
# https://turbo.hotwired.dev/handbook/drive#reloading-when-assets-change
12+
# 'data-turbo-track': reload
13+
# link_attributes:
14+
# Uncomment if using Turbo Drive
15+
# 'data-turbo-track': reload
16+
17+
# If using Encore.enableIntegrityHashes() and need the crossorigin attribute (default: false, or use 'anonymous' or 'use-credentials')
18+
# crossorigin: 'anonymous'
19+
20+
# Preload all rendered script and link tags automatically via the HTTP/2 Link header
21+
# preload: true
22+
23+
# Throw an exception if the entrypoints.json file is missing or an entry is missing from the data
24+
# strict_mode: false
25+
26+
# If you have multiple builds:
27+
# builds:
28+
# frontend: '%kernel.project_dir%/public/frontend/build'
29+
30+
# pass the build name as the 3rd argument to the Twig functions
31+
# {{ encore_entry_script_tags('entry1', null, 'frontend') }}
32+
33+
framework:
34+
assets:
35+
json_manifest_path: '%kernel.project_dir%/public/build/manifest.json'
36+
37+
#when@prod:
38+
# webpack_encore:
39+
# # Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
40+
# # Available in version 1.2
41+
# cache: true
42+
43+
#when@test:
44+
# webpack_encore:
45+
# strict_mode: false

generators/symfony/templates/base-twig/package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"devDependencies": {
99
"@babel/core": "^7.26.0",
1010
"@babel/preset-env": "^7.26.0",
11+
"@symfony/webpack-encore": "^5.0.1",
1112
"@thetribe/eslint-config": "^0.5.0",
1213
"autoprefixer": "^10.4.20",
1314
"babel-loader": "^9.2.1",
@@ -19,18 +20,19 @@
1920
"postcss": "^8.5.1",
2021
"postcss-loader": "^8.1.1",
2122
"sass": "^1.83.4",
22-
"sass-loader": "^13.3.3",
23+
"sass-loader": "^16.0.4",
2324
"stylelint": "^15.11.0",
2425
"stylelint-config-recommended-scss": "^11.0.0",
2526
"webpack": "^5.97.1",
2627
"webpack-cli": "^5.1.4",
27-
"webpack-dev-server": "^4.15.2",
28-
"webpack-manifest-plugin": "^5.0.0"
28+
"webpack-dev-server": "^4.15.2"
2929
},
3030
"scripts": {
31-
"build": "webpack",
31+
"build": "encore production --progress",
32+
"dev": "encore dev",
33+
"dev-server": "encore dev-server",
3234
"lint:js": "eslint assets webpack.config.js",
3335
"lint:scss": "stylelint 'assets/**/*.scss'",
34-
"start": "webpack-dev-server --host 0.0.0.0"
36+
"watch": "encore dev --watch"
3537
}
3638
}

generators/symfony/templates/base-twig/symfony.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,22 @@
483483
"config/routes/dev/web_profiler.yaml"
484484
]
485485
},
486+
"symfony/webpack-encore-bundle": {
487+
"version": "2.2",
488+
"recipe": {
489+
"repo": "github.com/symfony/recipes",
490+
"branch": "main",
491+
"version": "2.0",
492+
"ref": "35ee1edee91a1a7137095f53db7ed0c20884b745"
493+
},
494+
"files": [
495+
"assets/app.js",
496+
"assets/styles/app.css",
497+
"config/packages/webpack_encore.yaml",
498+
"package.json",
499+
"webpack.config.js"
500+
]
501+
},
486502
"symfony/yaml": {
487503
"version": "v4.3.3"
488504
},

generators/symfony/templates/base-twig/templates/base.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<meta charset="UTF-8">
55
<title>{% block title %}Symfony{% endblock %}</title>
66
{% block stylesheets %}
7-
<link rel="stylesheet" href="{{ asset('base.css') }}">
7+
{{ encore_entry_link_tags('base') }}
88
{% endblock %}
99
</head>
1010
<body>
1111
{% block body %}{% endblock %}
1212
{% block javascripts %}
13-
<script src="{{ asset('base.js') }}"></script>
13+
{{ encore_entry_script_tags('base') }}
1414
{% endblock %}
1515
</body>
1616
</html>

0 commit comments

Comments
 (0)