-
-
Notifications
You must be signed in to change notification settings - Fork 199
Closed as not planned
Closed as not planned
Copy link
Labels
Description
Version:
- symfony v5.2.7
- symfony/webpack-encore-bundle v1.11.2
I want to set the name of my assets with my real version name.
My prefered way would be to use enableVersioning
and generate the hash myself, but i didn't find how.
The hack i found is by replacing .enableVersioning(Encore.isProduction())
with :
.configureFilenames({
js: '[name].js?version=' + version,
css: '[name].css?version=' + version
})
Here is my webpack.config.js
file
var Encore = require('@symfony/webpack-encore');
// var version = require('./package.json').version;
// 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
*
* 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 your JavaScript imports CSS.
*/
.addEntry('app', './assets/app.js')
.addEntry('login', './assets/js/scenes/login.js')
.addEntry('home', './assets/js/scenes/home.js')
.addEntry('container', './assets/js/scenes/container.js')
.addEntry('aside', './assets/js/component/containerGroupSelector.js')
.addEntry('chart', './assets/js/component/containerMeasuresChart.js')
.addEntry('alerts', './assets/js/scenes/alertsList.js')
.addEntry('createAlert', './assets/js/scenes/createAlert.js')
.addEntry('profile', './assets/js/scenes/profile.js')
.addEntry('sensor', './assets/js/scenes/sensorList.js')
.addEntry('sensorShow', './assets/js/scenes/sensorShow.js')
//.addEntry('page2', './assets/page2.js')
// 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()
//.disableSingleRuntimeChunk()
/*
* 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())
// .configureFilenames({
// js: '[name].js?version=' + version,
// css: '[name].css?version=' + version
// })
// enables @babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
// refresh browser
.configureWatchOptions(function(watchOptions) {
// enable polling and check for changes every 250ms
// polling is useful when running Encore inside a Virtual Machine
watchOptions.poll = 250;
})
// enables Sass/SCSS support
.enableSassLoader()
.copyFiles({
from: './assets/images',
to: 'images/[path][name].[ext]',
pattern: /\.(png|jpg|jpeg|svg)$/
})
.copyFiles({
from: './assets/icon',
to: 'icon/[path][name].[ext]',
pattern: /\.(png|jpg|jpeg|svg)$/
})
// uncomment if you use TypeScript
//.enableTypeScriptLoader()
// 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()
// uncomment if you use API Platform Admin (composer req api-admin)
//.enableReactPreset()
//.addEntry('admin', './assets/admin.js')
;
module.exports = Encore.getWebpackConfig();
If I uncomment var version = require('./package.json').version;
and replace enableVersioning
by configureFilenames
(see above) I get the following error when building assets :
panel | (node:74) UnhandledPromiseRejectionWarning: Error: Problem deleting JS entry for _tmp_copy: 0 files were deleted
panel | at /var/www/panel/node_modules/@symfony/webpack-encore/lib/webpack/delete-unused-entries-js-plugin.js:41:27
panel | at Array.forEach (<anonymous>)
panel | at emit (/var/www/panel/node_modules/@symfony/webpack-encore/lib/webpack/delete-unused-entries-js-plugin.js:19:28)
panel | at AsyncSeriesHook.eval [as callAsync] (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:65:1)
panel | at AsyncSeriesHook.lazyCompileHook (/var/www/panel/node_modules/tapable/lib/Hook.js:154:20)
panel | at Compiler.emitAssets (/var/www/panel/node_modules/webpack/lib/Compiler.js:491:19)
panel | at onCompiled (/var/www/panel/node_modules/webpack/lib/Compiler.js:278:9)
panel | at /var/www/panel/node_modules/webpack/lib/Compiler.js:681:15
panel | at AsyncSeriesHook.eval [as callAsync] (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:4:1)
panel | at AsyncSeriesHook.lazyCompileHook (/var/www/panel/node_modules/tapable/lib/Hook.js:154:20)
panel | at /var/www/panel/node_modules/webpack/lib/Compiler.js:678:31
panel | at AsyncSeriesHook.eval [as callAsync] (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
panel | at AsyncSeriesHook.lazyCompileHook (/var/www/panel/node_modules/tapable/lib/Hook.js:154:20)
panel | at /var/www/panel/node_modules/webpack/lib/Compilation.js:1423:35
panel | at AsyncSeriesHook.eval [as callAsync] (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:7:1)
panel | at AsyncSeriesHook.lazyCompileHook (/var/www/panel/node_modules/tapable/lib/Hook.js:154:20)
panel | at /var/www/panel/node_modules/webpack/lib/Compilation.js:1414:32
panel | at eval (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:17:1)
panel | (node:74) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
panel | (node:74) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.