在 Laravel 中使用节点模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/32031627/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:12:07  来源:igfitidea点击:

Using node modules in Laravel

phplaravelnpmreactjs

提问by Anraiki

I am trying to include this module: https://www.npmjs.com/package/react-datepicker-componentwith react into my Laravel Framework.

我正在尝试包含这个模块:https: //www.npmjs.com/package/react-datepicker-component 并在我的 Laravel 框架中做出反应。

I went on to using npm to install it but I am getting no where after that.

我继续使用 npm 来安装它,但在那之后我无处可去。

I could use some direction. Has anyone tried using NPM for Laravel other than for Laravel Elixir?

我可以使用一些方向。除了 Laravel Elixir 之外,有没有人尝试过在 Laravel 上使用 NPM?

回答by coderp

I was stuck with this same issue for about an hour trying to pull in the inputmask node package.

我在尝试拉入 inputmask 节点包时遇到了同样的问题大约一个小时。

The only way I was able to get it included was by attaching it to the window object in app.js (similar to what bootstrap.js does)

我能够包含它的唯一方法是将它附加到 app.js 中的 window 对象(类似于 bootstrap.js 所做的)

window.InputMask = require('inputmask');

If you don't want to load it every time (as it would with app.js) you can create a separate js file that contains only the line of code above and load that on select pages. I feel like there has to be a better way, but this is the only way I've found to make it work.

如果您不想每次都加载它(就像使用 app.js 那样),您可以创建一个单独的 js 文件,其中只包含上面的代码行,并将其加载到选定的页面上。我觉得必须有更好的方法,但这是我找到的唯一方法。