简体   繁体   English

用供应商创建一个gulpfile.js

[英]create a gulpfile.js with vendor

I want to use Foundation with Magento2 but I am new to node. 我想将Foundation与Magento2一起使用,但是我是Node的新手。 I installed zurb/foundation with composer and it works if I run npm start or npm watch . 我在composer上安装了zurb / foundation,如果我运行npm startnpm watch ,它就可以工作。 I need to have files in app/design/frontend/package/theme/web. 我需要在app / design / frontend / package / theme / web中有文件。

I created a gulpfile.js to get things work and I try to import the things I need from the vendor directory but something is strange to me. 我创建了一个gulpfile.js来使工作正常进行,我尝试从供应商目录中导入所需的东西,但对我来说有些奇怪。

var path = require("path");
var base = path.normalize(__dirname + '/../../../../../../vendor/zurb/foundation/');

var gulp = require("gulp");

require("path") works but require("gulp") does not. require(“ path”)有效,但require(“ gulp”)无效。 If I try to make require(base + "gulp") it does not work either. 如果我尝试使require(base +“ gulp”)也不起作用。

I do not really understand why. 我真的不明白为什么。 If I install the gulp and other required modules in the same directory, it works but I think that it is not a really good way. 如果我将gulp和其他必需的模块安装在同一目录中,则可以使用,但我认为这不是一个很好的方法。

installing gulp globally (npm install -g gulp) will fix your problem but I think you should first understand why your problem is happening. 全局安装gulp(npm install -g gulp)将解决您的问题,但我认为您应该首先了解为什么会发生问题。

require uses a relative path from your parent directories to find package.json and node_modules so when you use require("path") that is globally installed from npm but gulp might not be. require使用父目录中的相对路径来查找package.json和node_modules,因此当您使用从npm全局安装但不是gulp的require(“ path”)时。

try installing gulp in your project with (npm install --save-dev gulp) and see so that the gulpfile.js is either in the same directory with node_modules or in the same parent (regarding if it's the child of another directory on the same level) 尝试使用(npm install --save-dev gulp)在项目中安装gulp,然后查看gulpfile.js处于与node_modules相同的目录中,或者位于相同的父目录中(无论它是同一目录中另一个目录的子目录)水平)

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

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