Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用gulp/package.json设置开发阶段_Json_Gulp_Package.json_Web Development Server - Fatal编程技术网

使用gulp/package.json设置开发阶段

使用gulp/package.json设置开发阶段,json,gulp,package.json,web-development-server,Json,Gulp,Package.json,Web Development Server,好的,所以我正在尝试一种新的设置,给我一种更有效的方法来开发我的网站 目前,我只能想到3个阶段:开发、阶段和构建 当我使用gulp时,我一直在终端中键入gulp,开始创建我的构建站点 我不想运行Gulp命令,而是想使用类似npm运行开发或npm运行阶段或npm运行构建 我通过键入Gulp了解,它会自动查找gulpfile.js文件。如何创建自己的文件 我知道这与package.json文件中的脚本有关,但我不知道如何解决 以下是我目前掌握的情况: { "name": "Name", "v

好的,所以我正在尝试一种新的设置,给我一种更有效的方法来开发我的网站

目前,我只能想到3个阶段:开发、阶段和构建

当我使用gulp时,我一直在终端中键入gulp,开始创建我的构建站点

我不想运行Gulp命令,而是想使用类似npm运行开发npm运行阶段npm运行构建

我通过键入Gulp了解,它会自动查找gulpfile.js文件。如何创建自己的文件

我知道这与package.json文件中的脚本有关,但我不知道如何解决

以下是我目前掌握的情况:

{
  "name": "Name",
  "version": "1.0.0",
  "description": "Description",
  "main": "index.html",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "development": "node builds/development.js",
    "staging": "node builds/staging.js",
    "build": "node builds/build.js"
  },
  "author": "Author name here",
  "license": "ISC",
  "devDependencies": {
    "gulp": "^4.0.2",
  },
  "dependencies": {
  }
}

现在,当我键入“npm run staging”(是gulpfile.js的一个精确副本)时,我希望它会像键入Gulp一样开始

更新: 这是我的大口文件

// --------------------------------------------
// Gulp Loader
// --------------------------------------------
// Stop having to put gulp. infront of the following
const {
  src,
  dest,
  task,
  watch,
  series,
  parallel
} = require("gulp");

// --------------------------------------------
// Dependencies
// --------------------------------------------

// HTML plugins
var htmlmin = require("gulp-htmlmin");

// CSS / SASS plugins
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');

// Images plugins
// let imagemin = require("gulp-imagemin");
var embedSvg = require("gulp-embed-svg");

// Browser plugins
var browserSync = require('browser-sync').create();

// Utility plugins
var plumber = require("gulp-plumber");
var rename = require("gulp-rename");
var cache = require('gulp-cache');
var autoprefixer = require('gulp-autoprefixer');
var sourcemaps = require('gulp-sourcemaps');
var shell = require('shelljs');
var uglify = require('gulp-uglify');
var del = require("del");
var inject = require('gulp-inject');
var shell = require('shelljs');
var noop = require('gulp-noop');
// --------------------------------------------
// Get Home Folder location
// --------------------------------------------
//Displays Users/User
const homedir = require("os").homedir();
// Needed for next part
var path = require("path");
//Displays Users/User/Documents/Clients/clientname/Projects (This is where I create my client folders)
var pathDir = require("path").resolve(__dirname, "../../");
var pathSrc = require("path").resolve(__dirname, "../../../");
//Display the name of the Clients folder name
var parentFld = path
  .dirname(pathDir)
  .split(path.sep)
  .pop();
var parentDir = path.basename(path.dirname(pathDir));
parentDir = parentFld.replace(/[^\w]/g, "");
parentDir = parentFld.replace(/[^\w]/g, "").toLowerCase();


// BrowserSync
function server(done) {
  browserSync.init({
    proxy: "http://" + parentDir + ".test",
    host: parentDir + ".test",
    open: "external",
    notify: false
  });
  done();
}

// function watcher() {
// Serve files from the root of this project
//  browserSync.init({
//    proxy: "https://" + parentdir + ".test",
// //   host: parentdir + ".test",
// open: "external",
//   https: {
//     key: homedir + "/.config/valet/Certificates/" + parentdir + ".test.key",
//    cert: homedir + "/.config/valet/Certificates/" + parentdir + ".test.crt"
// },
// browser: "Google Chrome Canary",
// notify: false
// });

// --------------------------------------------
// Paths
// --------------------------------------------
var paths = {
  htaccess: {
    src: './source/.htaccess',
    dest: './development/.htaccess',
  },
  html: {
    src: './source/*.html',
    prt: './source/partials/*.html',
    dest: './development/'
  },
  styles: {
    src: 'source/styles/*.css',
    dest: 'development/styles/'
  },
  scripts: {
    src: 'source/scripts/*.js',
    dest: 'development/scripts'
  }
}

// --------------------------------------------
// Tasks
// --------------------------------------------


//Basic task with a log - SHOW $homedir
function home(cb) {
  console.log(fontBld);
  cb()
}
task('default', function () {
  console.log('Hello World!');
});

//Basic task with a log
function ssg(cb) {
  console.log(parentDir);
  cb()
}

// CONSOLE LOG
function console_log(cb) {
  console.log(parentDir);
  cb()
}

function valet_link(cb) {
  shell.mkdir(['development']);
  shell.cd(['./development']);
  if (shell.exec('sudo valet link' + ' ' + parentDir).code !== 0) {
    shell.echo('Error: Git commit failed');
    shell.exit(1);
  }
  shell.cd(['..']);
  cb()
}

// CLEAN
function clean(cb) {
  del.sync(paths.html.dest, {
    force: true
  });
  cb()
}

// HT ACCESS
function htaccess() {
  return src(paths.htaccess.src)
    .pipe(dest(paths.htaccess.dest));
}

// HTML
function html() {
  var injectPartials = src(paths.html.prt, {
    relative: true
  });
  var injectStyles = src([paths.styles.src], {
    relative: true
  });
  var injectScripts = src(paths.scripts.src, {
    relative: true
  });
  return src(paths.html.src)
    .pipe(inject(injectPartials, {
      starttag: '<!-- inject:header:{{ext}} -->',
      transform: function (filePath, file) {
        // return file contents as string
        return file.contents.toString('utf8')
      }
    }))
    .pipe(inject(injectStyles, {
      addRootSlash: false,
      ignorePath: '/source/'
    }))
    .pipe(inject(injectScripts, {
      addRootSlash: false,
      ignorePath: '/source/'
    }))
    .pipe(
      embedSvg({
        root: "./source/images/",
        selectors: ".inline-svg"
      })
    )
    .pipe(dest(paths.html.dest));
}

// CSS
function css() {
  return src(paths.styles.src)

    .pipe(sass({
      outputStyle: 'compressed'
    }))
    .pipe(plumber())
    .pipe(dest(paths.styles.dest))
}

// JS
function js() {
  return src(paths.scripts.src)

    .pipe(
      rename({
        basename: "main",
        suffix: ".min"
      })
    )
    .pipe(plumber())
    .pipe(uglify())
    .pipe(dest(paths.scripts.dest));
}

// IMAGES
function img(done) {
  src(imageSrc + "*")
    .pipe(imagemin())
    .pipe(dest(imageDest));
  done();
}

// FONTS
function fonts(done) {
  src(fontSrc + "*").pipe(dest(fontDest));
  done();
}

function clearCache(done) {
  cache.clearAll();
  done();
}
// --------------------------------------------
// Watch
// --------------------------------------------
function watcher() {
  watch(paths.styles.src).on('change', series(css, browserSync.reload));
  watch(paths.scripts.src).on('change', series(js, browserSync.reload));
  watch(paths.htaccess.src).on('change', series(htaccess, browserSync.reload));
  watch(paths.html.src).on('change', series(html, browserSync.reload));
}

// --------------------------------------------
// Compile
// --------------------------------------------
exports.test = series(clean, html)
exports.log = console_log
exports.valet = valet_link
// --------------------------------------------
// Build
// --------------------------------------------
// CONSOLE LOG
function build_log(cb) {
  console.log("Please either use 'npm run production' or 'npm run development'");
  cb()
}

var compile = series(clean, valet_link, series(html, css, js));

task('default', series(compile, parallel(server, watcher)));
//--------------------------------------------
//大口装载机
// --------------------------------------------
//别再大口喝了。在下列情况之前
常数{
src,
目的地,
任务
看,,
系列
平行的
}=需要(“吞咽”);
// --------------------------------------------
//依赖关系
// --------------------------------------------
//HTML插件
var htmlmin=需要(“吞咽htmlmin”);
//CSS/SASS插件
var sass=需要('gulp-sass');
var cleanCSS=require('gulp-clean-css');
//图像插件
//让imagemin=require(“吞咽imagemin”);
var embedSvg=require(“gulp embed svg”);
//浏览器插件
var browserSync=require('browser-sync')。create();
//实用插件
var管道工=需要(“大口管道工”);
var rename=需要(“吞咽重命名”);
var cache=require('gulp-cache');
var autoprefixer=require('gulp-autoprefixer');
var sourcemaps=require('gulp-sourcemaps');
var shell=require('shelljs');
var-uglify=需要('gulp-uglify');
var del=要求(“del”);
var注入=需要('gulp-inject');
var shell=require('shelljs');
var noop=需要('gulp-noop');
// --------------------------------------------
//获取主文件夹位置
// --------------------------------------------
//显示用户/用户
const homedir=require(“os”).homedir();
//下一部分需要
var路径=要求(“路径”);
//显示用户/用户/文档/客户端/客户端名称/项目(这是我创建客户端文件夹的地方)
var pathDir=require(“路径”).resolve(_dirname,“../”);
var pathSrc=require(“path”).resolve(uu dirname,“../../../”);
//显示客户端文件夹名称的名称
var parentFld=路径
.dirname(路径目录)
.split(path.sep)
.pop();
var parentDir=path.basename(path.dirname(pathDir));
parentDir=parentFld.replace(/[^\w]/g,“”);
parentDir=parentFld.replace(/[^\w]/g,“”).toLowerCase();
//浏览器同步
功能服务器(完成){
browserSync.init({
代理:“http://“+parentDir+”.test”,
主机:parentDir+“.test”,
打开:“外部”,
通知:假
});
完成();
}
//函数观察程序(){
//从该项目的根目录提供文件
//browserSync.init({
//代理:“https://“+parentdir+”.test”,
////主机:parentdir+“.test”,
//打开:“外部”,
//https:{
//密钥:homedir+“/.config/valet/Certificates/”+parentdir+“.test.key”,
//证书:homedir+“/.config/valet/Certificates/”+parentdir+“.test.crt”
// },
//浏览器:“谷歌浏览器金丝雀”,
//通知:假
// });
// --------------------------------------------
//路径
// --------------------------------------------
变量路径={
htaccess:{
src:“./source/.htaccess”,
目标:'./development/.htaccess',
},
html:{
src:'./source/*.html',,
prt:“./source/partials/*.html”,
目的地:'/发展/'
},
风格:{
src:'source/styles/*.css',
目标:“开发/风格/”
},
脚本:{
src:'source/scripts/*.js',
目标:“开发/脚本”
}
}
// --------------------------------------------
//任务
// --------------------------------------------
//带有日志的基本任务-SHOW$homedir
功能主页(cb){
控制台日志(fontBld);
cb()
}
任务('default',函数(){
log('helloworld!');
});
//带有日志的基本任务
功能ssg(cb){
console.log(parentDir);
cb()
}
//控制台日志
功能控制台日志(cb){
console.log(parentDir);
cb()
}
功能代客泊车链接(cb){
shell.mkdir(['development']);
shell.cd(['/开发]);
if(shell.exec('sudo-valet-link'+''+parentDir).code!==0){
echo('Error:Git commit failed');
外壳。出口(1);
}
shell.cd(['..']);
cb()
}
//干净的
功能清洁(cb){
del.sync(path.html.dest{
原力:对
});
cb()
}
//高温通道
函数htaccess(){
返回src(path.htaccess.src)
.pipe(dest(path.htaccess.dest));
}
//HTML
函数html(){
var injectPartials=src(path.html.prt{
亲戚:是的
});
var injectStyles=src([path.styles.src]{
亲戚:是的
});
var injectScripts=src(path.scripts.src{
亲戚:是的
});
返回src(path.html.src)
.管道(注入){
开始标记:“”,
转换:函数(文件路径、文件){
//以字符串形式返回文件内容
返回file.contents.toString('utf8')
}
}))
.管道(注入){
addRootSlash:false,
ignorePath:'/source/'
}))
.管道(注入){
addRootSlash:false,
ignorePath:'/source/'
}))
.烟斗(
嵌入SVG({
根:“./source/images/”,
选择器:“.inline svg”
})
)
.pipe(dest(path.html.dest));
}
//CSS
函数css(){
返回src(path.styles.src)
.管道(sass)({
outputStyle:“压缩”
}))
.管子(管道工())
.pipe(dest(路径.样式.dest))
}
//JS
函数js(){
返回src(path.scripts.src)
.烟斗(
改名({
基本名称:“主要”,
后缀:“.min”
})
)
.管子(管道工())
.管道(ugli)
"scripts": {
    "gulp": "gulp",
    "test": "echo \"Error: no test specified\" && exit 1"
},
exports.development = function devFunction(){ ... };
exports.staging = function stagingFunction(){ ... };
exports.build = function buildFunction(){ ... };
gulp development