AdonisJs 4.0的新增功能

AdonisJS 4.0 has been in development for quite some time now. Recently Harminder Virk the creator of AdonisJs announced a dev release of the much awaited v4.0 of the framework. In his words:

AdonisJS 4.0已经开发了一段时间。 最近,AdonisJs的创建者Harminder Virk宣布了期待已久的框架v4.0的开发版本 。 用他的话说:

The framework is full of new and fresh ideas to make you even more productive

该框架充满了新的想法,使您的工作效率更高

In this article, we'll be looking at the new features, enhancements, changes that were introduced in AdonisJs 4.0. We'll start by highlighting them, then take a broader look at each of them in succession.

在本文中,我们将研究AdonisJs 4.0中引入的新功能,增强功能和更改。 我们将从突出显示它们开始,然后依次更广泛地查看它们。

  • New website design and logo

    新网站设计和徽标
  • Adonis CLI

    阿多尼斯CLI
  • NPM organization and scope packages

    NPM组织和范围包
  • Boilerplates

    样板
  • New directory structure

    新目录结构
  • ES6 features

    ES6功能
  • Speed Improvements

    速度改进
  • Edge Templating Engine

    边缘模板引擎

Visiting the dev release, you can’t help but notice the new and beautiful website design and logo.

访问开发版本 ,您不禁会注意到新的漂亮的网站设计和徽标。

AdonisJS now has a new theme (colors) which to me is really cooool. I like the new logo too.

现在,AdonisJS具有一个新主题(颜色),对我而言,这真的很酷。 我也喜欢新徽标。

阿多尼斯CLI ( Adonis CLI )

The Adonis CLI has being improved to include some additional functionality. The CLI now contain a install command which will save you tremendous time when installing npm packages. It does not only install the packages, but at the same time creates the config files, required models, migrations etc.

Adonis CLI进行了改进,以包括一些附加功能。 CLI现在包含一个install命令,它将在安装npm软件包时为您节省大量时间。 它不仅安装软件包,而且同时创建配置文件,所需的模型,迁移等。

NPM组织和范围包 ( NPM Organization and Scope Packages )

All AdonisJS packages are now grouped into an organisation and are scoped with @adonisjs prefix. This will make it easy to differentiate official AdonisJS packages from the community contributed packages. Below is how you would install AdonisJS Auth package:

现在,所有AdonisJS软件包都被分组到一个组织中,并以@adonisjs前缀为范围。 这将使区分官方的AdonisJS软件包和社区贡献的软件包变得容易。 以下是您如何安装AdonisJS Auth软件包的方法:

adonis install @adonisjs/auth

样板 ( Boilerplates )

It is somehow perceived that AdonisJS is meant for building only full stack applications. Well, that's not all true. AdonisJS can be used for any kind of applications ranging from full stack apps, building APIs to microservices. Hence, with v4.0 you have 3 boilerplates (fullstack, slim and api) which you can choose from when creating a new AdonisJS application. By defaut, the fullstack app boilerplate will be used but you can specify the boilerplate you want by passing --slim or --api-only flag.

人们以某种​​方式认为AdonisJS仅用于构建全栈应用程序。 好吧,这不是全部。 AdonisJS可用于各种应用程序,从全栈应用程序,构建API到微服务。 因此,在v4.0中,您有3个样板文件( fullstackslimapi ),可以在创建新的AdonisJS应用程序时选择。 通过defaut,将使用全栈应用样板,但您可以通过传递--slim--api-only标志来指定所需的样板。

// creates a fullstack app
adonis new app-name

// creates a slim app
adonis new app-name --slim

// creates an API only app
adonis new app-name --api-only

Now you can start building your application lean and grow big as the application permits.

现在,您可以开始构建精益应用程序,并在应用程序允许的情况下逐渐变大。

新目录结构 ( New Directory Structure )

There has been some significant changes in the way AdonisJS 4.0 apps are structured. Below is screenshot showing the directory structures of each boilerplate.

AdonisJS 4.0应用程序的结构方式已发生重大变化。 下面的屏幕截图显示了每个样板的目录结构。

Note that resources and public directories are not included in the api boilerplate, since the API you will be building with it can be consumed by any frontend or mobile app. You can easily create new directories/files as your application requires using the adonis CLI commands.

请注意, resourcespublic目录未包含在api模板中,因为您将使用它构建的API可以被任何前端或移动应用程序使用。 您可以使用adonis CLI命令轻松地根据应用程序的需要创建新的目录/文件。

ES6功能 ( ES6 Features )

AdonisJS 4.0 makes extensive use of async/await and ES6 Object destructuring. So if you are excited and love these ES6 features then you would definitely love AdonisJS 4.0. The code sample below shows how AdonisJS 4.0 makes use of these features:

AdonisJS 4.0大量使用了async/await和ES6对象解构。 因此,如果您兴奋并喜欢这些ES6功能,那么您一定会喜欢AdonisJS 4.0。 下面的代码示例显示了AdonisJS 4.0如何利用这些功能:

// sample code

class UserController {
    async login ({ request, auth }) {
        const { email, password } = request.all()
        await auth.attempt(email, password)

        return 'Logged in successfully'
    }
}

速度改进 ( Speed Improvements )

AdonisJS 4.0 uses async/await on like the eariler versions which makes use of generators. This has resulted in a huge performance significant in the framework, as v4.0 is almost 4 times faster than earlier versions of AdonisJS. You can take a look at the benchmarks.

AdonisJS 4.0像使用generators的伯爵版一样使用async/await 。 由于v4.0的速度比AdonisJS的早期版本快4倍 ,因此在框架中产生了巨大的性能。 您可以看一下基准测试

边缘模板引擎 ( Edge Templating Engine )

Edge.js is Node.js templating engine, it is blazing fast and comes with an elegant API to create dynamic views. It is created by the creator of AdonisJS. AdonisJS 4.0 makes use of Edge as its templating engine compared to eariler versions which makes use of nunjucks.

Edge.js是Node.js模板引擎,运行速度非常快,并带有优雅的API来创建动态视图。 它是由AdonisJS的创建者创建的。 与使用nunjucks的伯爵版相比,AdonisJS 4.0将Edge用作其模板引擎。

结论 ( Conclusion )

So we have taken a look the exciting things that are new to AdonisJS 4.0. Though it is hasn't be finally released, but the creator has clearly pointed out that the API is 100% complete. So you can start building your applications with AdonisJS 4.0 or start upgrading your existing applications. According to Harminder Virk, it's just some documentation that's left before it is officially released.

因此,我们看了看AdonisJS 4.0的新功能。 尽管尚未最终发布,但创建者明确指出该API已完成100%。 因此,您可以开始使用AdonisJS 4.0构建应用程序,也可以开始升级现有应用程序。 根据Harminder Virk的说法,这只是正式发布之前剩下的一些文档。

翻译自: https://scotch.io/tutorials/whats-new-in-adonisjs-40

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值