Webpack Encore包含外部js

时间:2019-06-22 19:40:15

标签: symfony webpack symfony4 webpack-encore

我有一个无法理解的问题:

webpack.config.js

Encore
    // directory where compiled assets will be stored
    .setOutputPath('public/build/')
    .copyFiles({
         from: './assets/media',
         // if versioning is enabled, add the file hash too
         to: 'media/[path][name].[hash:8].[ext]',
     })
    // 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/')


    .addEntry('app', ['./assets/js/app.js'])


    .splitEntryChunks()

    // will require an extra script tag for runtime.js
    // but, you probably want this, unless you're building a single-page app
    .enableSingleRuntimeChunk()

[...]     ;

app.js

// require jQuery normally
const $ = require('jquery');

// create global $ and jQuery variables
global.$ = global.jQuery = $;

require('../../assets/vendors/general/jquery/dist/jquery.js');
require('../../assets/vendors/general/popper.js/dist/umd/popper.js');
require('../../assets/vendors/general/bootstrap/dist/js/bootstrap.min.js');
require('../../assets/vendors/general/js-cookie/src/js.cookie.js');
require('../../assets/vendors/general/tooltip.js/dist/umd/tooltip.min.js');
require('../../assets/vendors/general/perfect-scrollbar/dist/perfect-scrollbar.js');
require('../../assets/vendors/general/sticky-js/dist/sticky.min.js');
require('../../assets/vendors/general/wnumb/wNumb.js');
require('../../assets/js/demo1/scripts.bundle.js');

require('../../assets/css/demo1/style.bundle.css');
require('../../assets/css/demo1/skins/header/base/light.css');
require('../../assets/css/demo1/skins/header/menu/light.css');
require('../../assets/css/demo1/skins/brand/dark.css');
require('../../assets/css/demo1/skins/aside/dark.css');

但是在我的页面上,我收到此错误:

  

jquery.js:3850未捕获ReferenceError:PerfectScrollbar不是   定义

我不明白为什么,因为非常需要完美的滚动条。如果我用导入做同样的事情。同样的事情是,如果我删除完美的滚动条,则会收到带有粘滞js的相同消息。

感谢您的帮助,

亚历克斯

1 个答案:

答案 0 :(得分:0)

Ok在Metronic支持下找到了解决方案:

Encore.addPlugin(new webpack.ProvidePlugin({
    PerfectScrollbar: require.resolve("perfect-scrollbar"),
}));