我在Symfony 4应用程序中使用Webpack Encore。现在的问题是我所需的js文件无法正常工作。下面是代码
webpack.config.js
const Encore = require('@symfony/webpack-encore');
Encore
.setOutputPath('public/build/')
.setPublicPath('/build')
.addEntry('app', './entry/app.js')
.enableSingleRuntimeChunk()
.cleanupOutputBeforeBuild()
.enableSourceMaps(!Encore.isProduction())
.enableVersioning(Encore.isProduction())
;
module.exports = Encore.getWebpackConfig();
app.js
require('../public/assets/js/custom/common.js');
require('../public/assets/js/page1.js');
common.js
function showLoader() {
//....
}
function hideLoader() {
//....
}
.......
page1.js
....
showLoader();
当我在HTML中使用app.js
文件并运行页面时,它将在控制台中引发错误
page1.js:1 Uncaught ReferenceError: showLoader is not defined
at Object../public/assets/js/page1.js (page1.js:1)
at __webpack_require__ (bootstrap:79)
at Object../entry/app.js (app.js:2)
at __webpack_require__ (bootstrap:79)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at app.js?version=10:1
我不想使用module.exports,因为我的common.js
具有50多个功能