简体   繁体   English

如何在Symfony2项目中对资产使用webshim?

[英]How to use webshim with assetic in a Symfony2 project?

I would like to use Webshim in a Symfony2 project. 我想在Symfony2项目中使用Webshim

So far, the webshim library is in mybundle/Resources/public/components/webshim... The webshim library has a polyfiller.js that loads specified scripts from the ./shims directory. 到目前为止,webshim库位于mybundle / Resources / public / components / webshim中。...webshim库具有polyfiller.js,可从./shims目录中加载指定的脚本。 This is also clearly explained from the webshim docs: webshim文档中也可以清楚地解释这一点:

The code inside of the polyfiller.js automatically detects the path to the script it is run from and assumes, that the shims folder is in the same directory. polyfiller.js内部的代码会自动检测运行脚本的路径,并假设shims文件夹位于同一目录中。 This means, you have to make sure, that either the shims folder is placed parallel to the code of the polyfiller.js or to configure the path using the basePath option. 这意味着您必须确保将shims文件夹放置在与polyfiller.js的代码平行的位置,或者使用basePath选项配置路径。

I'm using other libraries and they all end in the /web/js or /web/css directories as they should do. 我正在使用其他库,它们都应该以/ web / js或/ web / css目录结尾。 They are combined and have names like "6464de0.js" and are perfectly accessible. 它们结合在一起并具有类似“ 6464de0.js”的名称,并且可以轻松访问。

But, webshim tries to load scripts from the shims folder. 但是,webshim尝试从shims文件夹加载脚本。 This makes sense when you look at the docs. 当您查看文档时,这很有意义。

This is an example of 404's in the console: 这是控制台中404的示例:

GET http://domain.dev/app_dev.php/js/shims/combos/1.js 404 (Not Found) 

How can I make the webshim library work with assetic? 如何使Webshim库与Assetic一起使用?

I have the same issue and here is what I did: 我有同样的问题,这是我所做的:

Put the 'shims' folder in the public folder of your desired bundle (eg. AcmeBundle/Resources/public/js/shims) then when you do assets:install using the console command it will be installed in the Symfony/web directory. 将“ shims”文件夹放入所需捆绑软件的公用文件夹中(例如AcmeBundle / Resources / public / js / shims),然后在执行资产:使用控制台命令安装时,它将安装在Symfony / web目录中。

Then set the webshim option so that it points to that path: 然后设置webshim选项,使其指向该路径:

webshim.setOptions('basePath', '/bundles/acme/js/shims/');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM