UNPKG

2.13 kBJavaScriptView Raw
1// Copyright 2015 Esri
2// Licensed under The MIT License(MIT);
3// you may not use this file except in compliance with the License.
4// You may obtain a copy of the License at
5// http://opensource.org/licenses/MIT
6// Unless required by applicable law or agreed to in writing, software
7// distributed under the License is distributed on an "AS IS" BASIS,
8// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9// See the License for the specific language governing permissions and
10// limitations under the License.
11
12/* jshint node: true */
13'use strict';
14
15const ConvertToAMD = require('./lib/convert-to-amd-filter');
16
17module.exports = {
18
19 name: 'ember-cli-amd',
20
21 externalAmdModules: new Set(),
22 indexHtmlCache: {},
23
24 included(app) {
25 this._super.included.apply(this, arguments);
26
27 // Note: this function is only called once even if using ember build --watch or ember serve
28
29 // This is the entry point for this addon. We will collect the amd definitions from the ember-cli-build.js and
30 // we will build the list off the amd modules used by the application, replace define and require function calls
31 // in the js files and modify the index.html to load AMD loader first and all the external AMD modules before
32 // loading the vendor and app files.
33
34 // This addon relies on an 'amd' options in the ember-cli-build.js file and having a loader defined
35 if (!app.options.amd || !app.options.amd.loader) {
36 return;
37 }
38
39 // Merge the default options
40 this.amdOptions = Object.assign({
41 packages: [],
42 excludePaths: [],
43 loadingFilePath: 'assets'
44 }, app.options.amd);
45 },
46
47 postprocessTree(type, tree) {
48 if (!this.amdOptions) {
49 return tree;
50 }
51
52 if (type !== 'all') {
53 return tree;
54 }
55
56 // Note: this function will be called once during the continuous build.
57 // However, the tree returned will be directly manipulated by the continuous build.
58 let options = {
59 amdOptions: this.amdOptions,
60 rootURL: this.app.project.config(this.app.env).rootURL
61 }
62 return new ConvertToAMD(tree, options);
63 }
64};