# 发布

# mix.publish()

interface RenameOptions {
  dirname?: string;
  prefix?: string;
  basename?: string;
  suffix?: string;
  extname?: string;
}

interface TemplateOption {
  input: string;
  output: string;
  renameOptions: string | Function | RenameOptions;
}

mix.publish(input: string | TemplateOption[], output: string, renameOptions?: string | Function | RenameOptions)

从本地发布静态资源和模板到远程。

🌰 举个栗子:

  • 发布静态资源 (styles, scripts, images, fonts, media)
    • 输入:${roots.target}/{css,js,img,font,media}/**/*
    • 输出:${assets.root}/${assets.mainDir}/${assets.subDir}
const api = (mix) => {
  mix.publish();
};

module.exports = (balm) => {
  return {
    config: {},
    api
  };
};
  • 发布模板
    • 输入:${roots.target}/index.html
    • 输出:${assets.root}/views/new-filename.blade.php
const api = (mix) => {
  // 单模板
  mix.publish('index.html', 'views', {
    basename: 'new-filename',
    suffix: '.blade',
    extname: '.php'
  });

  // 多模板
  mix.publish([
    {
      input: 'index.html',
      output: 'views',
      renameOptions: {
        basename: 'new-filename',
        suffix: '.blade',
        extname: '.php'
      }
    }
    // 更多配置
  ]);
};

module.exports = (balm) => {
  return {
    config: {},
    api
  };
};

# mix.zip()

mix.zip(input: string | string[] = '', output = '', filename = 'archive.zip')

🌰 举个栗子:

const api = (mix) => {
  // 默认用法
  // 输入:'/path/to/project/dist/**/*'
  // 输出:'/path/to/project/archive.zip'
  mix.zip();

  // 附带 dotfile 的用法
  mix.zip(['dist/**/*', 'dist/.some-dotfile']);
};

module.exports = (balm) => {
  return {
    config: {},
    api
  };
};

# mix.ftp()

interface FtpConfig {
  host?: string;
  port?: number;
  username?: string;
  password?: string;
  remotePath?: string;
}

interface HookOptions {
  src?: object; // = `gulp.src`
  ftp?: FtpConfig;
}

mix.ftp(localFiles: string, options?: HookOptions)

🌰 举个栗子:

const config = {
  ftp: {
    options: {
      host: '192.168.1.1',
      port: 22,
      username: 'root',
      password: '',
      remotePath: '/path/to/webroot/project'
    }
  }
};

const api = (mix) => {
  //(本地)输入:'/path/to/project/dist/archive.zip'
  //(远程)输出:`${ftp.options.remotePath}/archive.zip`
  mix.ftp('dist/archive.zip');
  // OR
  mix.ftp('dist/archive.zip', {
    // FTP options: 覆盖 `balm.config.ftp.options` 配置
  });
};

module.exports = (balm) => {
  return {
    config,
    api
  };
};
Last Updated: 4 years ago