From 6159e332df8f24924fba06bbe1263bf1ff7509f0 Mon Sep 17 00:00:00 2001 From: toran billups Date: Fri, 6 Jul 2018 07:03:29 -0500 Subject: [PATCH] FEATURE: configuration to exclude components --- README.md | 14 +++++++++++++- addon/mixins/hot-reload-resolver.js | 12 +++++++++++- package.json | 1 + yarn.lock | 7 +++++++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d8907fe..a5f6b7e 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,18 @@ note: The HotReloadMixin is replaced with an empty Mixin for production/test bui After the ember install simply run `ember serve` as you normally would. Any changes to component JS/HBS files will result in a hot reload (not a full page reload). If you alter a route, service, controller or controller template ember-cli will do a full page reload. +## Excluding components + +If you want to exclude any component(s) from hot reloading simply configure them using `excluded` + +```javascript +//my-app/config/environment.js +if (environment === 'development') { + ENV['ember-cli-hot-loader'] = { + excluded: ['liquid-unless', 'liquid-child'] + } +} +``` ## Example application @@ -35,7 +47,7 @@ An example application that hot reloads styles/components/reducers https://github.com/toranb/ember-hot-reload-demo -## Configurations and Supported Types +## Supported Types * ember-cli will hot reload styles for you when using ember-cli 2.3+ * ember-cli-hot-loader will hot reload component JS/HBS changes diff --git a/addon/mixins/hot-reload-resolver.js b/addon/mixins/hot-reload-resolver.js index 6a30df4..fa956f4 100644 --- a/addon/mixins/hot-reload-resolver.js +++ b/addon/mixins/hot-reload-resolver.js @@ -1,6 +1,8 @@ import Mixin from '@ember/object/mixin'; import Component from '@ember/component'; import HotReplacementComponent from 'ember-cli-hot-loader/components/hot-replacement-component'; +import { get, computed } from '@ember/object'; +import config from 'ember-get-config'; import { captureTemplateOptions } from 'ember-cli-hot-loader/utils/clear-container-cache'; function removeOriginalFromParsedName (parsedName) { @@ -23,6 +25,10 @@ export default Mixin.create({ const resolved = this._super(...arguments); if (parsedName.type === 'component') { + const excluded = get(this, 'excluded'); + if (excluded.some((name) => name === parsedName.name)) { + return this._super(parsedName); + } if (resolved) { return this._resolveComponent(resolved, parsedName); } @@ -52,5 +58,9 @@ export default Mixin.create({ const templateFullName = `template:components/${parsedName.fullNameWithoutType}-original`; const templateParsedName = this.parseName(templateFullName); return this.resolveTemplate(templateParsedName) || this.resolveOther(templateParsedName); - } + }, + excluded: computed(function() { + const exclude = config['ember-cli-hot-loader']['excluded']; + return exclude || []; + }) }); diff --git a/package.json b/package.json index 9cb5e73..8e95da2 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ }, "dependencies": { "ember-cli-babel": "^6.6.0", + "ember-get-config": "^0.2.4", "broccoli-stew": "^1.5.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 34c3ed6..a26389a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2193,6 +2193,13 @@ ember-export-application-global@^2.0.0: dependencies: ember-cli-babel "^6.0.0-beta.7" +ember-get-config@^0.2.4: + version "0.2.4" + resolved "https://registry.npmjs.org/ember-get-config/-/ember-get-config-0.2.4.tgz#118492a2a03d73e46004ed777928942021fe1ecd" + dependencies: + broccoli-file-creator "^1.1.1" + ember-cli-babel "^6.3.0" + ember-load-initializers@^1.0.0: version "1.1.0" resolved "https://registry.npmjs.org/ember-load-initializers/-/ember-load-initializers-1.1.0.tgz#4edacc0f3a14d9f53d241ac3e5561804c8377978"