Symfony:Webpack Encore Require()不起作用?

时间:2017-12-18 10:04:22

标签: javascript symfony webpack-encore

我尝试使用Symfony Webpack Encore。这是我的app.js包含在我的默认控制器枝条中。我不能使用BootstrapDialog。

require("bootstrap");
require("bootstrap-dialog");

console.log("Hello");

$(function() {
    console.log( 'Hello with jquery' );
});

BootstrapDialog.alert('Hello from dialog');

输出:

app.js:6 Hello iam a asset
10:47:34.793 app.js:13 Uncaught ReferenceError: BootstrapDialog is not defined
at Object.<anonymous> (app.js:13)
at Object../app/Resources/public/js/app.js (app.js:28)
at __webpack_require__ (bootstrap 51bba752688cd28a7b76:54)
at webpackJsonpCallback (bootstrap 51bba752688cd28a7b76:25)
at app.js:1
(anonymous) @ app.js:13
./app/Resources/public/js/app.js @ app.js:28
__webpack_require__ @ bootstrap 51bba752688cd28a7b76:54
webpackJsonpCallback @ bootstrap 51bba752688cd28a7b76:25
(anonymous) @ app.js:1
10:47:34.810 app.js:9 Hello with jquery

npm list -g --depth = 0

/usr/local/Cellar/node/9.3.0_1/lib
├── bootstrap@3.3.7
├── bootstrap3-dialog@1.35.4
├── jquery@3.2.1
└── npm@5.6.0

1 个答案:

答案 0 :(得分:0)

你试过吗

var BootstrapDialog = require('bootstrap-dialog');

如果您想在app.js之外使用它,则可能需要另外添加类似

的内容
window.BootstrapDialog = BootstrapDialog;