Search code examples
symfonywebpackwebpack-encore

Preserve symbolic links Encore with cleanupOutputBeforeBuild


I have a symfony 4 project using webpack. When I run:

yarn encore dev --watch

it cleans the directory and delete the symbolic link.

I want to preserve the symbolic link, because a background process is writing on it files.

The symb link is created using:

ln -s /dev/shm/mpeg-dash /public/build/video

This is my webpack.config.js:

var webpack = require('webpack');

var Encore = require('@symfony/webpack-encore');
var CopyWebpackPlugin = require('copy-webpack-plugin');

Encore
//the project directory where compiled assets will be stored
.setOutputPath('public/build/')
//the public path used by the web server to access the previous directory
.setPublicPath('/build')
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())

//uncomment to define the assets of the project
.createSharedEntry('js/app', './assets/js/app.js')
.addEntry('js/profile', './assets/js/profile.js')
.addEntry('js/users', './assets/js/users-list.js')
.addEntry('js/blacklist', './assets/js/blacklist-index.js')
.addEntry('js/mailaddress', './assets/js/mailaddress.js')
.addEntry('js/vehicles', './assets/js/vehicles.js')
.addEntry('js/vehicles-form', './assets/js/vehicles-form.js')
.addEntry('js/vehicles-import', './assets/js/import-vehicles.js')
.addEntry('js/devices', './assets/js/devices.js')
.addEntry('js/devices-form', './assets/js/devices-form.js')
.addEntry('js/devices-show', './assets/js/devices-show.js')
.addEntry('js/detections', './assets/js/detections.js')
.addEntry('js/atex_vehicle', './assets/js/atex_vehicle.js')
.addEntry('js/atex_driver', './assets/js/atex_driver.js')
.addEntry('js/fdv', './assets/js/fdv-index.js')
.addEntry('js/statistics', './assets/js/statistics.js')
.addEntry('js/translation-overview', './assets/js/translation-overview.js')
.addEntry('js/grid', './assets/js/grid.js')
.addStyleEntry('css/app', './assets/css/app.scss')
.addStyleEntry('css/flags', './assets/css/flags.css')
.addPlugin(new CopyWebpackPlugin([
    {from: './assets/images', to: 'images'},
    {from: './assets/fonts', to: 'fonts'},
    {from: '././assets/js/jsmpeg.min.js', to: 'js/jsmpeg.min.js'},
    {from: '././assets/files/import', to: 'files/import'}
]))
.addPlugin(new webpack.ContextReplacementPlugin(/\.\/locale$/, 'empty-module', false, /js$/))
//uncomment if you use Sass/SCSS files
.enableSassLoader()
//uncomment for legacy applications that require $/jQuery as a global variable
.autoProvidejQuery();

var config = Encore.getWebpackConfig();

module.exports = config;

How can I avoid deleting this symbolic link.

Thanks.


Solution

  • I got with the solution with this code:

    .cleanupOutputBeforeBuild(['css/*', 'js/*', 'entrypoints.json', 'manifest.js', 'manifest.json'], (options) => {
        options.verbose = true;
        options.exclude = ['public/build/video/*'];
    
        return options;
    })