[英]How to get both JQuery-UI and datepicker localizations using NPM?
I am building a wonderful web application with Laravel, defining my javascript dependencies with the package.json
, and all is going well. 我建立与Laravel精彩的Web应用程序,定义与我的javascript依赖
package.json
,一切都很顺利。 Until when I need to use a JQuery datepicker with a default italian localization. 直到我需要使用具有默认意大利语本地化的JQuery日期选择器。
Looking in SO, I get a million of suggestions about JQuery-UI and localization, like JQuery UI datepicker localization , Localization not working in jQuery UI datePicker and jQuery UI Datepicker localization error on load . 看看SO,我得到了关于JQuery-UI和本地化的一百万条建议,比如JQuery UI datepicker本地化 , 本地化无法在jQuery UI datePicker中工作,jQuery UI Datepicker 本地化错误在加载时 。 Sadly, nothing about how to make it work with NPM and moreover with a localization file needed.
可悲的是,没有关于如何使其与NPM一起工作,而且还需要一个本地化文件。
I could download the source files and use them, but I managed to be tidy until now, and I'd love to find out how to use NPM for my datepicker too. 我可以下载源文件并使用它们,但直到现在我都设置得很整洁,我也想知道如何将NPM用于我的日期选择器。
After a ton of attempts, here is a working version. 经过大量的尝试,这是一个工作版本。
First of all, define all of the dependencies in package.json
首先,定义
package.json
所有依赖项
...
"jquery-ui-dist": "^1.12.1",
"jquery-ui": "^1.12.1",
...
Notice that I need BOTH the jquery-ui-dist
version (for the minimized version that we will use) and the jquery-ui
, for the localization file. 请注意,我既需要
jquery-ui-dist
版本(我们将使用最小化版本)和jquery-ui
,为本地化文件。
That said, I have to copy my files from the node_modules
folder (that I don't export in production) to the public/js
folder, and I do it adding these rows in webpack.mix.js
也就是说,我必须将我的文件从
node_modules
文件夹(我不在生产中导出)复制到public/js
文件夹,我在webpack.mix.js
添加这些行
...
.scripts('node_modules/jquery-ui-dist/jquery-ui.min.js','public/js/jquery-ui.min.js')
.scripts('node_modules/jquery-ui/ui/i18n/datepicker-it.js','public/js/datepicker-it.js')
...
Last but not least, I add the import of the javascript files in my page, 最后但同样重要的是,我在页面中添加了javascript文件的导入,
<script src="/js/jquery-ui.min.js"></script>
<script src="/js/datepicker-it.js"></script>
and this makes the trick, loading the datepicker in italian language by default 这就是诀窍,默认情况下用意大利语加载datepicker
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.