在上一篇中,我们基本简单搭建了一个工程。如上文所说,ember-cli插件,是基于broccoli.js 来进行资源管理以及目录结构管理的,所以说,了解目录结构对我们来说有很重要的意义,此外我们还是说道一些常用的配置。
ember工程目录结构
在使用ember new <project-name>
的时候,会将你的目录结构打出来,如下:
简单来说,如下所示,其中比较重要(或者说需要修改)的文件,用红色标出:
这里着重介绍2个文件
environment.js
以及ember-cli-build.js
以及顺带说一下.jshintrc
,route.js
environment.js
这个文件,顾名思义,主要用来配置和环境相关的内容,初始内容如下:
/* jshint node: true */
module.exports = function(environment) {
var ENV = {
modulePrefix: 'ember-demo',
environment: environment,
rootURL: '/',
locationType: 'auto',
EmberENV: {
FEATURES: {
}
},
APP: {
}
};
if (environment === 'development') {
}
if (environment === 'test') {
// Testem prefers this...
ENV.locationType = 'none';
// keep test console output quieter
ENV.APP.LOG_ACTIVE_GENERATION = false;
ENV.APP.LOG_VIEW_LOOKUPS = false;
ENV.APP.rootElement = '#ember-testing';
}
if (environment === 'production') {
}
return ENV;
};
(1)environment
环境,有三个值:production
development
test
,
(2)rootURL
根路径,默认为’/’,
(3)locationType
用来表示url的规则,有4中规则hash
history
auto
none
。
既然说到了这里,可以顺带说一下route.js
。这个文件,是用来做路由管理的,其中的有两个变量localtion
rootUrl
,一般,我们都会在这里,配置一下。如下:
import Ember from 'ember';
import config from './config/environment';
const Router = Ember.Router.extend({
location: config.locationType,