我如何在 Laravel 中使用节点模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39077660/
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
How I use node modules in laravel?
提问by Wolffyx
In my resource/assets/js I have tests.js ,I use gulp to build all files from js including this one ,in this file I have
在我的资源/资产/js 中,我有 tests.js,我使用 gulp 从 js 构建所有文件,包括这个文件,在这个文件中我有
var cmd = require('node-cmd');
cmd.get(
'echo 3',
function(data){
console.log('You are returning: ',data)
}
);`
I want to use this modulebut not in root directory in public directory or in other directory than root,is any possibility to use require funcion for example from public folder using gulp?
我想使用这个模块,但不是在公共目录的根目录中或在 root 之外的其他目录中,是否有可能使用 require 函数,例如从使用 gulp 的公共文件夹?
采纳答案by Loek
Use Elixir to mix your JavaScript files in your assets
folder into (1 app.js
file in) your public folder.
使用 Elixir 将文件assets
夹中的JavaScript 文件混合到app.js
公共文件夹中(1 个文件中)。
Take a look at the documentation on Elixir and JavaScript
Note however, that both NodeJS and php are server side technologies and you should really know what you're doing to make them work together. Pushing NodeJS libraries in your public folder to use client side is NOTwhat NodeJS is made for and you should probably not use it that way.
但是请注意,NodeJS 和 php 都是服务器端技术,您应该真正了解如何使它们协同工作。在公共文件夹中使用客户端推送图书馆的NodeJS是不是有什么是的NodeJS用于制作你可能不应该使用这种方式。