PHPackages                             ssch/typo3-encore - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ssch/typo3-encore

ActiveTypo3-cms-extension[Utility &amp; Helpers](/categories/utility)

ssch/typo3-encore
=================

Use Webpack Encore in TYPO3 Context

v6.0.1(11mo ago)107465.5k↓14.2%24[5 issues](https://github.com/sabbelasichon/typo3_encore/issues)[7 PRs](https://github.com/sabbelasichon/typo3_encore/pulls)4GPL-2.0-or-laterPHPPHP &gt;=8.1CI passing

Since May 6Pushed 3mo ago6 watchersCompare

[ Source](https://github.com/sabbelasichon/typo3_encore)[ Packagist](https://packagist.org/packages/ssch/typo3-encore)[ Fund](https://paypal.me/schreiberten)[ GitHub Sponsors](https://github.com/sabbelasichon)[ RSS](/packages/ssch-typo3-encore/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (20)Versions (55)Used By (4)

[![Downloads](https://camo.githubusercontent.com/2feb5e7bed2fb71111c1831e9e52ed0f031329bf331a5dcfe4d18e8292e38504/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f737363682f7479706f332d656e636f72652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/ssch/typo3-encore)

TYPO3 integration with Webpack Encore!
======================================

[](#typo3-integration-with-webpack-encore)

This extension allows you to use the `splitEntryChunks()` feature from [Webpack Encore](https://symfony.com/doc/current/frontend.html)by reading an `entrypoints.json` file and helping you render all of the dynamic `script` and `link` tags needed.

```
composer require ssch/typo3-encore

```

How to use
----------

[](#how-to-use)

1. First of all install Webpack Encore as stated in the [documentation](https://symfony.com/doc/current/frontend.html). You should really be able to use all of the things described in the documentation. Like Sass-Loader, Vue-Loader etc. These things are completely independent from this little extension.

You can also use the enableVersioning() of files (mostly used only in production context). You can also use the enableIntegrityHashes(). This is taking into account if the files are included.

2. Define your entry path(s) and the output path (usually your Resource/Public/ folder in your Package extension) in the webpack.config.js
3. Afterwards set the two TypoScript constants to point to the manifest.json and the entrypoints.json located in the configured output folder

```
plugin.tx_typo3encore {
    settings {
        entrypointJsonPath = EXT:typo3_encore/Resources/Public/entrypoints.json
        manifestJsonPath = EXT:typo3_encore/Resources/Public/manifest.json
    }
}
```

4. In your Page templates/layout you can then use the ViewHelpers to integrate the CSS- and JS-Files in your website

```
{namespace encore = Ssch\Typo3Encore\ViewHelpers}

```

If you have defined multiple entries you can define the desired entryName in the ViewHelpers

```
{namespace encore = Ssch\Typo3Encore\ViewHelpers}

```

Alternatively you can also include the files via TypoScript

```
page.includeCSS {
    # Pattern typo3_encore:entryName
    app = typo3_encore:app
    # If you want to ensure that this file is loaded first uncomment the next line
    # app.forceOnTop = 1
}

page.includeJS {
    # Pattern typo3_encore:entryName
    app = typo3_encore:app
    # If you want to ensure that this file is loaded first uncomment the next line
    # app.forceOnTop = 1
}

page.includeJSFooter {
    # Pattern typo3_encore:entryName
    app = typo3_encore:app
}
```

Note the prefix typo3\_encore: This is important in order to render the files correctly. You can then use all other known settings to include your files.

You don´t have to care about including it only once. This will not happen during one request cycle unless you want to.

It is also possible to use the inclusion via the prefix typo3\_encore in backend specific contexts. For example like so:

```

```

### HTTP/2 Preloading

[](#http2-preloading)

All css and javascript files managed by the extension will be added to the AssetRegistry class during rendering. For these assets a Link HTTP header is created, which are the key to optimize the application performance when using HTTP/2 and preloading capabilities of modern web browsers.

Technically this is done by a PSR-15 Middleware.

If you want to add additional files to the AssetRegistry you can use the PreloadViewHelper:

```
{namespace encore = Ssch\Typo3Encore\ViewHelpers}

```

Watch out, the example also uses the AssetViewHelper. The AssetViewHelper behind the scenes makes a look up to the manifest.json file. So you can also leverage the versioning feature provided by Webpack.

### Static assets

[](#static-assets)

Sometimes you might need to reference static assets (like image files) directly in your fluid templates. You can use the Encore `copyFiles` function to instruct Webpack to copy static assets to your output folder (see ).

To reference a static asset file from a fluid template, you can then use the AssetViewHelper to get the file path (including the hash if versioning is enabled).

Note that the AssetViewHelper does not render anything but just returns the path to the file, so you will probably use inline notation to, e.g., display an image:

```
{namespace encore = Ssch\Typo3Encore\ViewHelpers}

```

This way of using the AssetViewHelper is similar to the `asset` function used in Twig templates with Symfony.

Additional
----------

[](#additional)

1. If you are in production mode and set enableVersioning(true) then you should set the option

    ```
    $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename'] = ''
    ```
2. Defining Multiple Webpack Configurations ([see](https://symfony.com/doc/current/frontend/encore/advanced-config.html#defining-multiple-webpack-configurations))

    Then you have to define your builds in your TypoScript-Setup:

    ```
     plugin.tx_typo3encore {
         settings {
             builds {
                 firstBuild = EXT:typo3_encore/Resources/Public/FirstBuild
                 secondBuild = EXT:typo3_encore/Resources/Public/SecondBuild
             }
         }
     }
    ```

    Finally, you can specify which build to use:

    ```
     page.includeCSS {
         # Pattern typo3_encore:buildName:entryName
         app = typo3_encore:firstBuild:app
     }
    ```

    ```
     {namespace encore = Ssch\Typo3Encore\ViewHelpers}

    ```
3. **Important note on TYPO3 JS/CSS concatenation and compression while working with encore dev-server mode**

    If you are using the Encore dev server (`encore dev-server`), ensure that TYPO3's asset concatenation and compression are disabled.

    Enabling these options (`config.concatenateCss = 1`, `config.concatenateJs = 1`, `config.compressCss = 1`, or `config.compressJs = 1`) will prevent the dev server's hot module replacement (HMR) from working correctly. Additionally, TYPO3 may produce a large volume of temporary files (potentially gigabytes), significantly slowing down Docker-based development environments.

    See [Issue #234](https://github.com/sabbelasichon/typo3_encore/issues/234) for more details.

    Example TypoScript to disable concatenation/compression in Development:

    ```
    [like(applicationContext, "Development*")]
      config {
        compressCss = 0
        concatenateCss = 0
        compressJs = 0
        concatenateJs = 0
      }
    [global]

    ```

### CSS for CKEditor

[](#css-for-ckeditor)

It is possible to configure encore so that you can use a CSS file for the CKEditor which is generated by webpack and even works with enabled versioning. Two steps are required to do so:

1. Define an entrypoint for the RTE in your `webpack.config.js`, e.g.

```
Encore
    .addStyleEntry('rte', './assets/rte.scss')
```

2. Add in the CKEditor yaml configuration

```
editor:
  config:
    contentsCss: "typo3_encore:rte"
```

Getting Started with Webpack Encore
-----------------------------------

[](#getting-started-with-webpack-encore)

Although the documentation of Webpack Encore is awesome, i am going to provide a minimalistic how to install the frontend related things. I assume some basic knowledge of modern frontend development.

### Install Encore into your project via Yarn or Npm:

[](#install-encore-into-your-project-via-yarn-or-npm)

First, make sure you install [Node.js](https://nodejs.org/en/download/) and also the [Yarn](https://yarnpkg.com/lang/en/docs/install/) or [npm](https://www.npmjs.com/get-npm) package manager.

```
yarn add @symfony/webpack-encore --dev

```

This command creates or modifies a package.json file and downloads dependencies into a node\_modules/ directory. Yarn also creates/updates a yarn.lock (called package-lock.json if you use npm).

You should commit package.json and yarn.lock (or package-lock.json if using npm) to version control, but ignore the node\_modules/ folder.

### Creating the webpack.config.js File

[](#creating-the-webpackconfigjs-file)

Next, we are going to create a webpack.config.js file at the root of our project. This is the main config file for both Webpack and Webpack Encore:

```
var Encore = require('@symfony/webpack-encore');

Encore
    // the directory where compiled assets will be stored
    .setOutputPath('public/typo3conf/ext/my_sitepackage/Resources/Public/')

    // public path used by the web server to access the output path
    .setPublicPath('/typo3conf/ext/my_sitepackage/Resources/Public/')

    // only needed for CDN's or sub-directory deploy
    // .setManifestKeyPrefix('build/')

    // Copy some static images to your -> https://symfony.com/doc/current/frontend/encore/copy-files.html
    .copyFiles({
        from: './src/images',
        // Optional target path, relative to the output dir
        to: 'images/[path][name].[ext]',
        includeSubdirectories: false,
        // if versioning is enabled, add the file hash too
        to: 'images/[path][name].[hash:8].[ext]',
        // only copy files matching this pattern
        pattern: /\.(png|jpg|jpeg)$/
    })

    /*
     * 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 you JavaScript imports CSS.
     */
    .addEntry('app', './src/js/app.js')
    .addEntry('homepage', './src/js/homepage.js')

    // will require an extra script tag for runtime.js
    // but, you probably want this, unless you're building a single-page app
    .enableSingleRuntimeChunk()

    .cleanupOutputBeforeBuild()
    .enableSourceMaps(!Encore.isProduction())

    // enables hashed filenames (e.g. app.abc123.css)
    .enableVersioning(Encore.isProduction())

    // uncomment if you use TypeScript -> https://symfony.com/doc/current/frontend/encore/typescript.html
    // .enableTypeScriptLoader()

    // uncomment if you are using Sass/SCSS files -> https://symfony.com/doc/current/frontend/encore/css-preprocessors.html
    // .enableSassLoader()

    // uncomment if you're having problems with a jQuery plugin -> https://symfony.com/doc/current/frontend/encore/legacy-applications.html
    // .autoProvidejQuery()

    // uncomment if you use the postcss -> https://symfony.com/doc/current/frontend/encore/postcss.html
    // .enablePostCssLoader()

    // uncomment if you want to use vue -> https://symfony.com/doc/current/frontend/encore/vuejs.html
    // .enableVueLoader()

    // uncomment if you´re want to lint your sources
    // .enableEslintLoader()

    // uncomment if you´re want to have integrity hashes for your script tags, the extension takes care of it
    // .enableIntegrityHashes()

    // uncomment if you´re want to share general code for the different entries -> https://symfony.com/doc/current/frontend/encore/split-chunks.html
    // .splitEntryChunks()
    ;

// Uncomment if you are going to use a CDN -> https://symfony.com/doc/current/frontend/encore/cdn.html
// if (Encore.isProduction()) {
    //Encore.setPublicPath('https://my-cool-app.com.global.prod.fastly.net');

    // guarantee that the keys in manifest.json are *still*
    // prefixed with build/
    // (e.g. "build/dashboard.js": "https://my-cool-app.com.global.prod.fastly.net/dashboard.js")
    // Encore.setManifestKeyPrefix('build/');
// }

module.exports = Encore.getWebpackConfig();
```

### Working with Watcher &amp; TYPO3 with Content Security Policy

[](#working-with-watcher--typo3-with-content-security-policy)

If you encounter problems with Content Security Policy and watcher add the following to your additional.php

```
// disable CSP if "npm run watch" is used
if (strpos(file_get_contents(\TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/build/entrypoints.json'), 'build/vendors-node_modules') !== false) {
    $GLOBALS['TYPO3_CONF_VARS']['SYS']['features']['security.frontend.enforceContentSecurityPolicy'] = false;
}
```

### Working with typo3/cms-composer-installers 4+ or TYPO3 12

[](#working-with-typo3cms-composer-installers-4-or-typo3-12)

The `typo3/cms-composer-installers` library takes care of moving TYPO3-specific assets in the right place in Composer-based installations, like copying extensions to `typo3conf/ext`. Starting with version 4.0 (currently at RC1 stage), the extensions will remain in `vendor/vendor_name`. The `Resources/Public`directory of each extension is symlinked from the `public/assets` directory using hashes. While it is possible to target the symlink, the fact that it is a hash makes it a bit flaky.

The recommendation is to use another build directory, not located inside an extension. As an example, asuming that you use `public/build`, the configuration in `webpack.config.js`would be modified as follows:

```
var Encore = require('@symfony/webpack-encore');

Encore
    .setOutputPath('../../public/build')
    .setPublicPath('/build')
    ...
```

The TypoScript constants have to be modified accordingly:

```
plugin.tx_typo3encore {
    settings {
        # These paths are relative to the web root (public) directory
        entrypointJsonPath = build/entrypoints.json
        manifestJsonPath = build/manifest.json
    }
}

```

If the site `base` configuration (`config/sites/yoursite/config.yaml`) is a subdirectory/subpath of your domain, it is required to add your new "build" directory as an additional absolute directory. This can be done in your "Configure Installation-Wide Options" (TYPO3 &lt;= 11: `typo3conf/LocalConfiguration.php`; TYPO3 &gt;= 12: `config/system/settings.php`)

```
    [FE][additionalAbsRefPrefixDirectories]: build

```

### The realm of Webpack plugins

[](#the-realm-of-webpack-plugins)

Encore already ships with a lot of useful plugins for the daily work. But someday you are gonna get to the point where you need more.

#### Generating icons and inject them automatically

[](#generating-icons-and-inject-them-automatically)

Install [webapp-webpack-plugin](https://github.com/brunocodutra/webapp-webpack-plugin) and [html-webpack-plugin](https://github.com/jantimon/html-webpack-plugin).

```
const WebappWebpackPlugin = require('webapp-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');

Encore.addPlugin(new HtmlWebpackPlugin(
            {
                inject: false,
                minify: false,
                template: 'public/typo3conf/ext/typo3_encore/Resources/Private/Templates/Favicons.html',
                filename: 'favicons.html',
            }
        ))
        .addPlugin(new WebappWebpackPlugin({
            inject: htmlPlugin => htmlPlugin.options.filename === 'favicons.html',
            logo: './src/images/logo.png',
            force: true,
            favicons: {
                start_url: null,
                lang: null,
                icons: {
                    android: true,
                    appleIcon: true,
                    appleStartup: true,
                    windows: true,
                    yandex: true,
                    favicons: true,
                    coast: true,
                    firefox: true,
                    opengraph: false,
                    twitter: false
                }
            }
        }))
```

In order to inject the html file in the header of your TYPO3 just include the template file:

```
page.headerData.2039 = FLUIDTEMPLATE
page.headerData.2039 {
    file = EXT:typo3_encore/Resources/Public/favicons.html
}
```

#### Generating a svg sprite

[](#generating-a-svg-sprite)

Install [svg-sprite-loader](https://github.com/kisenka/svg-sprite-loader#installation)

```
const SpritePlugin = require('svg-sprite-loader/plugin');

Encore.addLoader({
    test: /\src\/icons\/.svg$/,
    loader: 'svg-sprite-loader',
    options: {
        extract: true,
    }
}).addPlugin(new SpritePlugin())
```

Now you have to import all your svg files in your javascript

```
function requireAll(r) {
    r.keys().forEach(r);
}
requireAll(require.context('./relative-path-to-svg-folder/svg-sprite/', true, /\.svg$/));

```

The extension ships with a SvgViewHelper in order to simplify the usage of svg in fluid.

```
{namespace encore = Ssch\Typo3Encore\ViewHelpers}

```

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance66

Regular maintenance activity

Popularity52

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 78.6% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~49 days

Recently: every ~187 days

Total

46

Last Release

349d ago

Major Versions

1.4.x-dev → v2.0.02020-01-16

2.x-dev → v3.0.02020-12-31

v3.0.9 → v4.0.02021-09-16

4.x-dev → v5.0.02022-12-16

v5.0.7 → v6.0.02024-10-21

PHP version history (8 changes)v1.0PHP ^7.1

v1.1PHP ^7.0

v2.0.0PHP &gt;=7.2.0 &lt;7.4

v2.0.2PHP &gt;=7.2.0 &lt;8.0

v2.3.0PHP &gt;=7.2.5 &lt;8.0

v3.0.0PHP &gt;=7.3

3.x-devPHP &gt;=7.4

v6.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/bebdadb696b19cbbca63cd296ae4e4f48bcf42c20bc483d7b4d0599836dc753d?d=identicon)[schreiberten](/maintainers/schreiberten)

---

Top Contributors

[![sabbelasichon](https://avatars.githubusercontent.com/u/13050560?v=4)](https://github.com/sabbelasichon "sabbelasichon (242 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (41 commits)")[![infabo](https://avatars.githubusercontent.com/u/3999104?v=4)](https://github.com/infabo "infabo (5 commits)")[![rvock](https://avatars.githubusercontent.com/u/209159?v=4)](https://github.com/rvock "rvock (4 commits)")[![georgringer](https://avatars.githubusercontent.com/u/1905663?v=4)](https://github.com/georgringer "georgringer (3 commits)")[![cweiske](https://avatars.githubusercontent.com/u/59036?v=4)](https://github.com/cweiske "cweiske (2 commits)")[![straschek-io](https://avatars.githubusercontent.com/u/22239902?v=4)](https://github.com/straschek-io "straschek-io (1 commits)")[![svenpet90](https://avatars.githubusercontent.com/u/97380444?v=4)](https://github.com/svenpet90 "svenpet90 (1 commits)")[![TheNaderio](https://avatars.githubusercontent.com/u/25088164?v=4)](https://github.com/TheNaderio "TheNaderio (1 commits)")[![Tobi77](https://avatars.githubusercontent.com/u/7982900?v=4)](https://github.com/Tobi77 "Tobi77 (1 commits)")[![bjo3rnf](https://avatars.githubusercontent.com/u/1183009?v=4)](https://github.com/bjo3rnf "bjo3rnf (1 commits)")[![websi](https://avatars.githubusercontent.com/u/2857262?v=4)](https://github.com/websi "websi (1 commits)")[![fpodschwadek](https://avatars.githubusercontent.com/u/93463918?v=4)](https://github.com/fpodschwadek "fpodschwadek (1 commits)")[![fsuter](https://avatars.githubusercontent.com/u/328984?v=4)](https://github.com/fsuter "fsuter (1 commits)")[![kszymukowicz](https://avatars.githubusercontent.com/u/1453553?v=4)](https://github.com/kszymukowicz "kszymukowicz (1 commits)")[![mueller-sebastian](https://avatars.githubusercontent.com/u/20316366?v=4)](https://github.com/mueller-sebastian "mueller-sebastian (1 commits)")[![rintisch](https://avatars.githubusercontent.com/u/44193208?v=4)](https://github.com/rintisch "rintisch (1 commits)")

---

Tags

encorees6hacktoberfestjavascripttypo3webpackwebpackencore

###  Code Quality

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/ssch-typo3-encore/health.svg)

```
[![Health](https://phpackages.com/badges/ssch-typo3-encore/health.svg)](https://phpackages.com/packages/ssch-typo3-encore)
```

###  Alternatives

[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[maba/webpack-bundle

Bundle to Integrate Webpack to Symfony

123268.2k4](/packages/maba-webpack-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
