安装 jspm 命令行界面。 jspm 是客户端依赖项的包管理器。阅读它......它很棒。
npm install jspm -g
为项目创建一个文件夹。
mkdir minimal
cd minimal
初始化jspm客户端包管理...
接受所有默认值,除了使用 Babel 转译器选项(与 Traceur 相比)
jspm init
通过将以下行添加到 config.js 中的 babelOptions(jspm init 创建 config.js 文件)来启用所有花哨的尖端 babel 优点:
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
创建一个 index.html,它使用 SystemJS 加载器(jspm 的模块加载器对应部分)来引导 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 引导时,它会寻找默认视图和视图模型...创建它们:
app.js
export class App {
message = 'hello world';
}
app.html
<template>
${message}
</template>
安装 gulp 和 browser-sync 以提供文件:
npm install gulp
npm install --save-dev browser-sync
添加一个 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);
});
启动网络服务器。
gulp serve
浏览到应用程序:
http://localhost:9000
完成。
以下是您完成后的项目结构:
注意:这只是一个快速而肮脏的设置。它不一定是推荐的文件夹结构,并且加载器正在使用 babel 即时转译 js 文件。您需要根据自己的需要对其进行微调。这里的目的是向您展示如何以尽可能少的步骤启动和运行。