@abcnews/aunty 中文文档教程

发布于 3年前 浏览 20 项目主页 更新于 3年前

@abcnews/aunty

用于处理 ABC 新闻项目的工具包

Installation

要使用 CLI 创建新项目,请在全局安装最新的 aunty 版本:

npm install --global @abcnews/aunty

基于 aunty 项目模板的项目已经将 aunty 列为本地依赖项,锁定到用于创建它的版本。

Usage

有关使用说明,请运行不带参数的 aunty,或有关特定命令的详细信息,请运行:

aunty help <command>

CLI 包含四种类型的命令,按用途分组:

  • Creating new projects (new, init)
  • Generating stuff (generate) like components
  • Developing projects (clean, build, serve, test)
  • Deploying (un)versioned projects (deploy, release)

Starting projects

创建新项目时,您应该使用全局 < strong>aunty:

/some/parent/directory $ aunty new

或者,从一个(最好是空的)目录中:

/some/parent/directory/my-project $ aunty init

Developing projects

在安装了 aunty 依赖项的项目目录中工作时,您将自动运行该本地 aunty

/some/parent/directory/my-project $ aunty <build|serve|...> [options]

这确保对未来版本的阿姨的任何更改都不会影响您的项目,并且您可以在准备好适应这些更改时手动更新本地阿姨。

项目级命令可以使用可选配置,您可以从项目级 aunty.config.js 文件中导出:

module.exports = {
  type: '<project_type>',
  // aunty command configuration
  build: {…},
  serve: {…},
  deploy: {…},
  // internal tools configuration
  babel: {…},
  jest: {…},
  webpack: {…},
  webpackDevServer: {…}
};

...或添加到您的 package.json 文件作为 aunty 属性:

"aunty": {
  "type": "<project_type>",
  "build": {…},
  "serve": {…},
  "deploy": {…},
  "babel": {…},
  "jest": {…},
  "webpack": {…},
  "webpackDevServer": {…}
}

支持的项目 type(当前:basicpreactreact & svelte) 有自己的默认构建配置,但您可以通过扩展项目配置来覆盖它。

buildservedeploy 属性允许您覆盖这些相应命令的默认设置。

Aunty 内部使用了一些工具,您也可以为其提供自定义配置。 如果您为 babeljestwebpack 和/或 webpackDevServer 属性提供一个对象,该对象将合并到默认配置中。 或者,您可以提供一个函数(针对任何属性),该函数将传递默认配置供您手动修改和返回。

如果您想查看任何命令(及其内部工具)的默认配置,或者您添加的内容的影响,您始终可以使用 --dry(或 -d)标志:

/some/parent/directory/my-project $ aunty serve --dry

应谨慎使用覆盖,因为当我们不偏离默认值时,使用单一依赖工具包的优势最为明显。

如果您不需要覆盖任何项目默认值,您的整个阿姨配置可以是一个包含项目类型的字符串,作为 {type: ""} 的简写。 type 是您的阿姨配置中唯一必需的属性。

Generators

Aunty 带有一些基本的发电机。 运行 aunty generate --help 获取完整列表,或 aunty generate; --help 了解更多详情。

Async/await

async/await 和 generators/yield 添加到项目的一种方法是使用 regenerator-runtime 包。

npm install regenerator-runtime 然后:

import 'regenerator-runtime/runtime';

注意:您可能还需要用于 IE11 的 Promise polyfill。

Multiple entry points

默认情况下,Aunty 在 src/ 中查找 index.js。 通过将 build::entry 配置添加到 aunty.config.js 来启用多个入口点。

Replace 'index' with 'story'

module.exports = {
  build: {
    entry: 'story' // will now also support `['story']`
  }
};

Replace 'index' with 'story', 'editor', 'graphic' & 'polyfills'

module.exports = {
  build: {
    entry: ['story', 'editor', 'graphic', 'polyfills']
  }
};

Retain 'index'; add 'editor', 'graphic' & 'polyfills'

module.exports = {
  build: {
    entry: ['index', 'editor', 'graphic', 'polyfills']
  }
};

Authors

Thanks

这个项目最初的灵感来自 nwb,这是 强尼布坎南。 如果您希望开发自己的工具包,Jonny 创建了一个很棒的指南 来帮助您入门。

@abcnews/aunty

A toolkit for working with ABC News projects

Installation

To use the CLI to create new projects, install the latest aunty release globally:

npm install --global @abcnews/aunty

Projects based on aunty's project templates already have aunty listed as a local dependency, locked to the version used to create it.

Usage

For usage instructions, run aunty with no arguments, or for details on specific commands, run:

aunty help <command>

The CLI contains four types of command, grouped by purpose:

  • Creating new projects (new, init)
  • Generating stuff (generate) like components
  • Developing projects (clean, build, serve, test)
  • Deploying (un)versioned projects (deploy, release)

Starting projects

When creating new projects, you should be using the global aunty:

/some/parent/directory $ aunty new

or, from within a (preferably empty) directory:

/some/parent/directory/my-project $ aunty init

Developing projects

When working inside a project directory that has the aunty dependency installed, you'll automatically be running that local aunty:

/some/parent/directory/my-project $ aunty <build|serve|...> [options]

This ensures that any changes to future versions of aunty won't impact your project, and you can manually update the local aunty when you're ready to accommodate those changes.

Project-level commands can use an optional configuration, which you can either export from a project-level aunty.config.js file:

module.exports = {
  type: '<project_type>',
  // aunty command configuration
  build: {…},
  serve: {…},
  deploy: {…},
  // internal tools configuration
  babel: {…},
  jest: {…},
  webpack: {…},
  webpackDevServer: {…}
};

…or add to your package.json file as an aunty property:

"aunty": {
  "type": "<project_type>",
  "build": {…},
  "serve": {…},
  "deploy": {…},
  "babel": {…},
  "jest": {…},
  "webpack": {…},
  "webpackDevServer": {…}
}

Supported project types (currently: basic, preact, react & svelte) have their own default build configuration, but you can override it by extending your project configuration.

The build, serve and deploy properties allow you to override the default settings for those respective commands.

Aunty uses some tools internally, which you can also provide custom configuration for. If you supply an object for the babel, jest, webpack, and/or webpackDevServer properties, that object will be merged into the default configuration. Optionally, you can supply a function (for any property), which will be passed the default configuration for you to manually modify and return.

If you're looking to see what the default configuration is for any command (and their internal tools), or the impact of your additions, you can always perform a dry run of the command by using the --dry (or -d) flag:

/some/parent/directory/my-project $ aunty serve --dry

Overrides should be used sparingly, as the advantages of using a single-dependency toolkit are most apparent when we don't deviate far from the defaults.

If you don't need to override any of the project defaults, your entire aunty configuration can be a string containing the project type, as a shorthand for {type: "<project_type>"}. type is the only required property in your aunty configuration.

Generators

Aunty comes with a few basic generators. Run aunty generate --help for the full list, or aunty generate <generator> --help for further details.

Async/await

One way to add async/await and generators/yield to your project is with the regenerator-runtime package.

npm install regenerator-runtime and then:

import 'regenerator-runtime/runtime';

Note: You may also need a Promise polyfill for IE11.

Multiple entry points

By default Aunty looks for index.js in src/. Enable multiple entry points by adding a build::entry config to aunty.config.js.

Replace 'index' with 'story'

module.exports = {
  build: {
    entry: 'story' // will now also support `['story']`
  }
};

Replace 'index' with 'story', 'editor', 'graphic' & 'polyfills'

module.exports = {
  build: {
    entry: ['story', 'editor', 'graphic', 'polyfills']
  }
};

Retain 'index'; add 'editor', 'graphic' & 'polyfills'

module.exports = {
  build: {
    entry: ['index', 'editor', 'graphic', 'polyfills']
  }
};

Authors

Thanks

This project was originally inspired by nwb, a React/Preact/Inferno toolkit by Jonny Buchanan. If you're looking to develop your own toolkit, Jonny's created a fantastic guide to get you started.

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文