问题描述
版本:
- symfony v5.2.7
- symfony/webpack-encore-bundle v1.11.2
我更喜欢的方法是使用 enabLeversioning
并自己生成哈希,但我没有找到方法。
我发现的 hack 是将 .enabLeversioning(Encore.isProduction())
替换为:
.configureFilenames({
js: '[name].js?version=' + version,css: '[name].css?version=' + version
})
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();
如果我取消注释 var version = require('./package.json').version;
并将 enabLeversioning
替换为 configureFilenames
(见上文),我在构建资产时会收到以下错误:
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.
更新:
将节点包@symfony/webpack-encore
升级到 1.3.0 后,以下是新的错误消息:
[webpack-cli] HookWebpackerror: Problem deleting JS entry for _tmp_copy: 0 files were deleted ()
at makeWebpackerror (/var/www/panel/node_modules/webpack/lib/HookWebpackerror.js:49:9)
at /var/www/panel/node_modules/webpack/lib/Compilation.js:2496:12
at eval (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:79:1)
at fn (/var/www/panel/node_modules/webpack/lib/Compilation.js:427:17)
at Hook.eval [as callAsync] (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:76:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/panel/node_modules/tapable/lib/Hook.js:18:14)
at cont (/var/www/panel/node_modules/webpack/lib/Compilation.js:2493:34)
at /var/www/panel/node_modules/webpack/lib/Compilation.js:2539:10
at /var/www/panel/node_modules/neo-async/async.js:2830:7
at Object.each (/var/www/panel/node_modules/neo-async/async.js:2850:39)
-- inner error --
Error: Problem deleting JS entry for _tmp_copy: 0 files were deleted ()
at /var/www/panel/node_modules/@symfony/webpack-encore/lib/webpack/delete-unused-entries-js-plugin.js:49:27
at Set.forEach (<anonymous>)
at deleteEntries (/var/www/panel/node_modules/@symfony/webpack-encore/lib/webpack/delete-unused-entries-js-plugin.js:18:28)
at /var/www/panel/node_modules/@symfony/webpack-encore/lib/webpack/delete-unused-entries-js-plugin.js:59:17
at /var/www/panel/node_modules/webpack/lib/Compilation.js:531:56
at fn (/var/www/panel/node_modules/webpack/lib/Compilation.js:425:10)
at Hook.eval [as callAsync] (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:76:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/panel/node_modules/tapable/lib/Hook.js:18:14)
at cont (/var/www/panel/node_modules/webpack/lib/Compilation.js:2493:34)
at /var/www/panel/node_modules/webpack/lib/Compilation.js:2539:10
caused by plugins in Compilation.hooks.processAssets
Error: Problem deleting JS entry for _tmp_copy: 0 files were deleted ()
at /var/www/panel/node_modules/@symfony/webpack-encore/lib/webpack/delete-unused-entries-js-plugin.js:49:27
at Set.forEach (<anonymous>)
at deleteEntries (/var/www/panel/node_modules/@symfony/webpack-encore/lib/webpack/delete-unused-entries-js-plugin.js:18:28)
at /var/www/panel/node_modules/@symfony/webpack-encore/lib/webpack/delete-unused-entries-js-plugin.js:59:17
at /var/www/panel/node_modules/webpack/lib/Compilation.js:531:56
at fn (/var/www/panel/node_modules/webpack/lib/Compilation.js:425:10)
at Hook.eval [as callAsync] (eval at create (/var/www/panel/node_modules/tapable/lib/HookCodeFactory.js:33:10),<anonymous>:76:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/var/www/panel/node_modules/tapable/lib/Hook.js:18:14)
at cont (/var/www/panel/node_modules/webpack/lib/Compilation.js:2493:34)
at /var/www/panel/node_modules/webpack/lib/Compilation.js:2539:10
error Command Failed with exit code 2.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)