Skip to content

Commit 4786b9f

Browse files
committed
[WebpackEncore] Add recipe for 7.0
1 parent fbeadd7 commit 4786b9f

7 files changed

Lines changed: 206 additions & 0 deletions

File tree

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Welcome to your app's main JavaScript file!
3+
*
4+
* We recommend including the built version of this JavaScript file
5+
* (and its CSS file) in your base layout (base.html.twig).
6+
*/
7+
8+
// any CSS you import will output into a single css file (app.css in this case)
9+
import './styles/app.css';
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
body {
2+
background-color: lightgray;
3+
}
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
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"bundles": {
3+
"Symfony\\WebpackEncoreBundle\\WebpackEncoreBundle": ["all"]
4+
},
5+
"copy-from-recipe": {
6+
"assets/": "assets/",
7+
"config/": "%CONFIG_DIR%/",
8+
"package.json": "package.json",
9+
"webpack.config.js": "webpack.config.js"
10+
},
11+
"aliases": ["encore", "webpack", "webpack-encore"],
12+
"gitignore": [
13+
"/node_modules/",
14+
"/%PUBLIC_DIR%/build/",
15+
"npm-debug.log",
16+
"yarn-error.log"
17+
],
18+
"conflict": {
19+
"symfony/framework-bundle": "<5.4",
20+
"symfony/flex": "<1.20.0 || >=2.0.0,<2.3.0"
21+
},
22+
"add-lines": [
23+
{
24+
"file": "templates/base.html.twig",
25+
"content": [
26+
" {{ encore_entry_script_tags('app') }}"
27+
],
28+
"position": "after_target",
29+
"target": "{% block javascripts %}",
30+
"warn_if_missing": true
31+
},
32+
{
33+
"file": "templates/base.html.twig",
34+
"content": [
35+
" {{ encore_entry_link_tags('app') }}"
36+
],
37+
"position": "after_target",
38+
"target": "{% block stylesheets %}",
39+
"warn_if_missing": true
40+
}
41+
]
42+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"devDependencies": {
3+
"@babel/core": "^8.0.0",
4+
"@babel/preset-env": "^8.0.0",
5+
"@symfony/webpack-encore": "^7.0.0",
6+
"babel-plugin-polyfill-corejs3": "^1.0.0",
7+
"core-js": "^3.49.0",
8+
"regenerator-runtime": "^0.13.9",
9+
"webpack": "^5.82",
10+
"webpack-cli": "^7.0.0"
11+
},
12+
"license": "UNLICENSED",
13+
"private": true,
14+
"scripts": {
15+
"dev-server": "encore dev-server",
16+
"dev": "encore dev",
17+
"watch": "encore dev --watch",
18+
"build": "encore production --progress"
19+
}
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
* Install NPM and run <fg=green>npm install</>
2+
3+
* Compile your assets for development: <fg=green>npm run dev</>
4+
5+
* Compile your assets for development and watch for any modifications: <fg=green>npm run watch</>
6+
7+
* Or start the development server: <fg=green>npm run dev-server</>
8+
9+
* Compile your assets for production: <fg=green>npm run build</>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import Encore from '@symfony/webpack-encore';
2+
3+
// Manually configure the runtime environment if not already configured yet by the "encore" command.
4+
// It's useful when you use tools that rely on webpack.config.js file.
5+
if (!Encore.isRuntimeEnvironmentConfigured()) {
6+
Encore.configureRuntimeEnvironment(process.env.NODE_ENV || 'dev');
7+
}
8+
9+
Encore
10+
// directory where compiled assets will be stored
11+
.setOutputPath('public/build/')
12+
// public path used by the web server to access the output path
13+
.setPublicPath('/build')
14+
// only needed for CDN's or subdirectory deploy
15+
//.setManifestKeyPrefix('build/')
16+
17+
/*
18+
* ENTRY CONFIG
19+
*
20+
* Each entry will result in one JavaScript file (e.g. app.js)
21+
* and one CSS file (e.g. app.css) if your JavaScript imports CSS.
22+
*/
23+
.addEntry('app', './assets/app.js')
24+
25+
// When enabled, Webpack "splits" your files into smaller pieces for greater optimization.
26+
.splitEntryChunks()
27+
28+
// will require an extra script tag for runtime.js
29+
// but, you probably want this, unless you're building a single-page app
30+
.enableSingleRuntimeChunk()
31+
32+
/*
33+
* FEATURE CONFIG
34+
*
35+
* Enable & configure other features below. For a full
36+
* list of features, see:
37+
* https://symfony.com/doc/current/frontend.html#adding-more-features
38+
*/
39+
.cleanupOutputBeforeBuild()
40+
41+
// Displays build status system notifications to the user
42+
// .enableBuildNotifications()
43+
44+
.enableSourceMaps(!Encore.isProduction())
45+
// enables hashed filenames (e.g. app.abc123.css)
46+
.enableVersioning(Encore.isProduction())
47+
48+
// Configure JS and CSS minimizers
49+
// .configureJsMinimizerPlugin((options, MinimizerPlugin) => {
50+
// options.minify = MinimizerPlugin.esbuildMinify
51+
// })
52+
// .configureCssMinimizerPlugin((options, MinimizerPlugin) => {
53+
// options.minify = MinimizerPlugin.lightningCssMinify;
54+
// })
55+
56+
// configure Babel
57+
.configureBabel((config) => {
58+
config.plugins.push(['polyfill-corejs3', { method: 'usage-global', version: '3.49' }]);
59+
})
60+
61+
// enables Sass/SCSS support
62+
//.enableSassLoader()
63+
64+
// uncomment if you use TypeScript
65+
//.enableTypeScriptLoader()
66+
67+
// uncomment if you use React
68+
//.enableReactPreset()
69+
70+
// uncomment to get integrity="..." attributes on your script & link tags
71+
// requires WebpackEncoreBundle 1.4 or higher
72+
//.enableIntegrityHashes(Encore.isProduction())
73+
74+
// uncomment if you're having problems with a jQuery plugin
75+
//.autoProvidejQuery()
76+
;
77+
78+
export default await Encore.getWebpackConfig();

0 commit comments

Comments
 (0)