Javascript Symfony,网页,点击事件仅在产品环境中执行两次
我使用Javascript Symfony,网页,点击事件仅在产品环境中执行两次,javascript,php,symfony,webpack,Javascript,Php,Symfony,Webpack,我使用symfony/frameworkbundle 5.0.5和“symfony/webpack encore bundle”:“dev master” 当我在dev env中开发代码时,一切都是正确的,但当我将项目切换到prod环境时,我遇到了奇怪的行为,我的onlick事件执行了两次,可能是双重的,包括我不理解的js脚本,当我返回dev env时,问题就消失了。如何在prod env的symfony框架中正确使用web包 webpack.config.js var Encore = req
symfony/frameworkbundle 5.0.5
和“symfony/webpack encore bundle”:“dev master”
当我在dev env中开发代码时,一切都是正确的,但当我将项目切换到prod环境时,我遇到了奇怪的行为,我的onlick事件执行了两次,可能是双重的,包括我不理解的js脚本,当我返回dev env时,问题就消失了。如何在prod env的symfony框架中正确使用web包
webpack.config.js
var Encore = require('@symfony/webpack-encore');
// 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/js/app.js')
.addEntry('index/js/index.min', './assets/js/index/index.js')
.addEntry('index/js/awin.min', './assets/js/index/awin.js')
.addEntry('index/js/adtraction.min', './assets/js/index/adtraction.js')
.addEntry('index/js/adrecord.min', './assets/js/index/adrecord.js')
.addEntry('index/js/tradeDoubler.min', './assets/js/index/tradeDoubler.js')
.addEntry('index/js/hover_menu.min', './assets/js/index/hover_menu.js')
.addEntry('index/js/brand_list.min', './assets/js/index/brand_list.js')
.addEntry('index/js/admin_shop_rule_list.min', './assets/js/index/admin_shop_rule_list.js')
.addEntry('index/js/resource_shop_list.min', './assets/js/index/resource_shop_list.js')
.addEntry('index/js/statisticsMonitoring.min', './assets/js/index/statisticsMonitoring.js')
//.addEntry('page1', './assets/js/page1.js')
//.addEntry('page2', './assets/js/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()
/*
* 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())
// enables @babel/preset-env polyfills
.configureBabelPresetEnv((config) => {
config.useBuiltIns = 'usage';
config.corejs = 3;
})
// enables Sass/SCSS support
.enableSassLoader()
.addStyleEntry('index/css/index.min', './assets/css/app.scss')
// 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/js/admin.js')
;
module.exports = Encore.getWebpackConfig();
config/packages/prod/webpack_encore.yaml
webpack_encore:
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
# Available in version 1.2
cache: true
webpack_encore:
# The path where Encore is building the assets - i.e. Encore.setOutputPath()
output_path: '%kernel.project_dir%/public/build'
config/packages/webpack_encore.yaml
webpack_encore:
# Cache the entrypoints.json (rebuild Symfony's cache when entrypoints.json changes)
# Available in version 1.2
cache: true
webpack_encore:
# The path where Encore is building the assets - i.e. Encore.setOutputPath()
output_path: '%kernel.project_dir%/public/build'
我的基本小枝模板只有用于fosjsrouting
{% block javascripts %}
<script src="{{ asset('bundles/fosjsrouting/js/router.min.js') }}"></script>
<script src="{{ path('fos_js_routing_js', { callback: 'fos.Router.setData' }) }}"></script>
{% endblock %}
我仔细检查了一遍,只检查了一次事件,在dev env中它工作正常。
对于我执行的服务器中的prod env
php bin/console c:c && yarn encore production && chmod 777 -R
var/cache/ var/log/
结果
Done in 13.51s.
如何解决