繁体   English   中英

安装后找不到 gulp 运行命令

[英]gulp run command not found after installing

我是新来gulp ,我只是创造一个gulpfile.js 我正在尝试运行gulp run但我得到了-bash: gulp: command not found

不确定为什么会发生这种情况,因为我在本地安装了它。

包.json:

{
  "name": "taglr",
  "version": "1.0.0",
  "description": "",
  "scripts": {
    "start": "webpack --config webpack.config.js && node ./build/index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "babel": "^6.5.2",
    "babel-core": "^6.7.2",
    "babel-loader": "^6.2.4",
    "deepmerge": "^0.2.10",
    "glue": "^3.2.0",
    "hapi": "^13.2.1",
    "jquery": "^2.2.1",
    "react": "^0.14.7",
    "react-dom": "^0.14.7",
    "react-router": "^2.0.1"
  },
  "devDependencies": {
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-react": "^6.5.0",
    "extract-text-webpack-plugin": "^1.0.1",
    "gulp": "^3.9.1",
    "nodemon": "^1.9.1",
    "webpack": "^1.12.14",
    "webpack-dev-server": "^1.14.1"
  }
}

gulpfile.js:

var gulp = require('gulp');
var webpack = require('webpack');
var path = require('path');
var fs = require('fs');
var DeepMerge = require('deep-merge');
var nodemon = require('nodemon');


// for excluding the building of node_modules in the backend
var nodeModules = {};
fs.readdirSync('node_modules').filter(function(x) {
    return ['.bin'].indexOf(x) === -1;
}).forEach(function(mod) {
    nodeModules[mod] = 'commonjs ' + mod;
});

// generic config
var defaultConfig = {
    module: {
        loaders: [
            {
                test: /\.js$/,
                exclude: /node_modules/,
                loader: 'babel-loader',
                query: {
                    presets: [
                        'react',
                        'es2015'
                    ]
                }
            }
        ]
    }
};

// if not production build
if (process.env.NODE_ENV !== 'production') {
    defaultConfig.devtool = '#eval-source-map';
    defaultConfig.debug = true
}

// build config using overrides
function buildConfig(config) {
    return DeepMerge(defaultConfig, config || {});
}


var backendConfig = buildConfig({
    entry: path.resolve(__dirname, "server/server.js"),
    // tells webpack not to touch any built-in modules
    target: "node",
    externals: nodeModules,
    output: {
        path: path.resolve(__dirname, "build"),
        filename: 'index.js'    
    },
    pluguns: [

    ]
});

var host = "localhost";
var port = 3000;

var frontendConfig = buildConfig({
    entry: path.resolve(__dirname, "app/index.js"),
    output: {
        path: path.resolve(__dirname, "public/bundle"),
        filename: "main.js"
        // publicPath: 'http://' + host + ':' + port + 'pubic/bundle'
    },
    plugins: [

    ]
});

function onBuild(done) {
    return function(err, stats) {
        if (err) {
            console.log("ERROR: " + err);
        } else {
            console.log(stats.toString());
        }
        if (done) {
            done(); 
        }
    }

}

// build frontend
gulp.task('build-frontend', function(done) {
    webpack(frontendConfig).run(onBuild(done));
});

// watch frontend
gullp.task('watch-frontend', function(done) {
    webpack(frontendConfig).watch(100, onBuild());
});

// build backend
gulp.task('build-backend', function(done) {
    webpack(backendConfig).run(onBuild(done));
});

// watch backend
gullp.task('watch-backend', function(done) {
    webpack(backendConfig).watch(100, function(err, stats) {
        onBuild()(err, stats);
        nodemon.restart();
    });
});


gulp.task('build', ['build-frontend', 'build-backend']);
gulp.task('watch', ['watch-frontend', 'watch-backend']);
gulp.task('run', ['watch-frontend', 'watch-backend'], function() {
    nodemon({
        execMap: {
            js: 'node'
        },

        script: 'build/index.js',
        ext: 'js html'
    })
});

问题是在$PATH任何目录中都找不到可执行的gulp 如果您全局安装它,它将被复制到/usr/lib/node_modules$PATH其他目录中(取决于您的发行版),因此只需使用:

npm install -g gulp-cli

或者如果你在那台机器上不能使用sudo ,你可以将它安装到你的项目 package.json 中:
npm install --save-dev gulp-cli

链接它:
ln -s node_modules/.bin/gulp gulp

使用本地符号链接执行它:
./gulp run

暂无
暂无

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

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