如何从头开始建立最小的Aurelia项目 [英] How to set up minimal Aurelia project from scratch

查看:42
本文介绍了如何从头开始建立最小的Aurelia项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安装Aurelia导航框架应用程序时,它所使用的所有第3方模块和现成的脚本都不堪重负.对于那些对理论上的大部分内容都有很好了解的我来说,当我一次无法做到这一点时,就很难学习.出于这个原因,我想自己建立一个最小的Aurelia项目,然后在进行过程中增加它的复杂性.

When installing the Aurelia navigation skeleton app it is far to overwhelming with all the 3rd party modules and ready-made scripts it uses. For me who have a good picture of what most of it is in theory, have a hard time learning when I can't do it one step at a time. For this reason I would like to set up a minimal Aurelia project by myself and then add complexity to it as I go along.

主要问题:建立一个简单的Aurelia项目需要哪些步骤?

Main question: Which steps are necessary to set up a simple Aurelia project?

假设:

  • 我已经有一个可以提供文件的Node服务器后端.
  • 我想使用ES6/7(Babel).
  • 我想使用system.js进行模块加载.
  • 没有单元或e2e测试,没有样式,没有文档.
  • 尽可能少的node和jspm模块.

还请对每个步骤进行一些说明,并说明所需的Aurelia文件是什么.

Please do also explain a little on each step and describe what the necessary Aurelia files is and does.

非常感谢您的帮助:)

推荐答案

安装jspm命令行界面. jspm是用于客户端依赖项的程序包管理器.继续阅读...很棒.

Install the jspm command line interface. jspm is a package manager for client-side dependencies. Read up on it... it's great.

npm install jspm -g

为项目创建一个文件夹.

Create a folder for the project.

mkdir minimal
cd minimal

初始化jspm客户端软件包管理... 接受所有默认值,除了使用Babel Transpiler选项(相对于Traceur)

Initialize jspm client package management... Accept all the defaults EXCEPT use the Babel transpiler option (vs Traceur)

jspm init

通过在config.js(jspm init创建config.js文件)的babelOptions中添加以下行来启用所有花哨的前沿babel善良功能:

Enable all the fancy cutting edge babel goodness by adding the following line to the babelOptions in your config.js (jspm init created the config.js file):

System.config({
  defaultJSExtensions: true,
  transpiler: "babel",
  babelOptions: {
    "stage": 0,      <------ add this to turn on the hotness
    "optional": [
      "runtime"
    ]
  },
  ...

安装Aurelia

jspm install aurelia-framework
jspm install aurelia-bootstrapper

创建一个使用SystemJS加载器(jspm的模块加载器对等部分)来引导Aurelia的index.html.

Create an index.html that uses the SystemJS loader (jspm's module loader counter-part) to bootstrap Aurelia.

<!doctype html>
<html>
  <head>
    <title>Aurelia</title>
  </head>
  <body aurelia-app>
    <h1>Loading...</h1>

    <script src="jspm_packages/system.js"></script>
    <script src="config.js"></script>
    <script>
      System.import('aurelia-bootstrapper');
    </script>
  </body>
</html>

Aurelia引导时,它将查找默认视图和视图模型...创建它们:

When Aurelia bootstraps it's going to look for a default view and view-model... create them:

app.js

export class App {
  message = 'hello world';
}

app.html

<template>
  ${message}
</template>

安装gulp和浏览器同步以提供文件:

Install gulp and browser-sync to serve the files:

npm install gulp
npm install --save-dev browser-sync

添加gulpfile.js

Add a gulpfile.js

var gulp = require('gulp');
var browserSync = require('browser-sync');

// this task utilizes the browsersync plugin
// to create a dev server instance
// at http://localhost:9000
gulp.task('serve', function(done) {
  browserSync({
    open: false,
    port: 9000,
    server: {
      baseDir: ['.'],
      middleware: function (req, res, next) {
        res.setHeader('Access-Control-Allow-Origin', '*');
        next();
      }
    }
  }, done);
});

启动Web服务器.

gulp serve

浏览到应用程序:

http://localhost:9000

完成.

这是您完成后的项目结构:

Here's what your project structure will look like when you're finished:

注意:这只是一个快速而肮脏的设置.不一定是推荐的文件夹结构,并且加载程序正在使用babel即时转换js文件.您将需要对此进行微调.这里的目的是向您展示如何以最少的步骤启动和运行.

Note: this is just a quick and dirty setup. It's not necessarily the recommended folder structure, and the loader is using babel to transpile the js files on the fly. You'll want to fine tune this to your needs. The intent here is to show you how to get up and running in the fewest steps possible.

这篇关于如何从头开始建立最小的Aurelia项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆