-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strip stuff from addon before it is added to app #4048
Conversation
Ok, so I tested this locally: # checkout ember-data from PR and link to npm
git clone https://github.com/emberjs/data.git
cd data
hub checkout https://github.com/emberjs/data/pull/4048
npm link
# create new ember app using linked ember-data
cd ..
ember new my-app --skip-bower --skip-npm
cd my-app
bower install
bower uninstall ember-data --save
bower install ember-cli/ember-cli-shims#0.1.0 --save
npm link ember-data
npm install
# create build and check if dist/assets/vendor.js contains correctly stripped ember-data
ember build All the debug statements from There is a problem though: all the ember-data modules in define('ember-data/-private/adapters/build-url-mixin', function () {
'use strict';
define('ember-data/-private/adapters/build-url-mixin', ['exports', 'ember'], function (exports, _ember) {
var get = _ember['default'].get;
// ...
});
}); EDIT: the problem has been fixed with help from the sharp eyes of @rwjblue. |
@@ -49,10 +49,20 @@ module.exports = { | |||
return { inputTree: dir, rebuild: function() { return []; } }; | |||
} | |||
|
|||
var version = require('./lib/version'); | |||
var merge = require('broccoli-merge-trees'); | |||
// TODO only return stripped code if we are in production environment? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (process.env.EMBER_ENV !== 'production') {
var strippedAddonCode = strippedBuild('ember-data', dir, {
blacklist: ['es6.modules', 'useStrict']
});
return this._super.treeForAddon.call(this, strippedAddonCode);
} else {
return this._super.treeForAddon.call(this, merge([version(), dir]));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙏
This looks good to me, and I'd like to see this land even without the features.json work done. The debug statement stripping in production will affect [email protected] when we release it, but since 2.3.x doesn't include features yet the Thoughts on landing this into beta, and iterating on it for 2.4.0-beta.x series for the feature flag stripping? |
@pangratz do you mind squashing these commits and prefix the commit message with |
@pangratz - this doesn't work unless the following are moved to dependencies (instead of devDependencies) - at least that's what I found (im using ember-cli-deploy though) Here's a compare: https://github.com/pangratz/data/compare/fix-ember-addon-production...eriktrom:fix-ember-addon-production Otherwise, looks good and works for me Thanks for tackling this |
Awesome catch @eriktrom! Thanks for testing! Looks like a ember new my-app --skip-bower --skip-npm
cd my-app
bower install
bower uninstall ember-data --save
bower install ember-cli/ember-cli-shims#0.1.0 --save
npm install pangratz/data#fix-ember-addon-production
npm install
ember build --prod |
Strip stuff from addon before it is added to app
Currently the code of the
ember-data
addon is added to the app. This is problematic since the code containsassert
,debug
, etcetera calls and also no feature flag code is stripped.This PR is my stab at fixing this, so only the stripped code is added via the
treeForAddon
hook inindex.js
.This addresses #4047 and takes inspiration from @fivetanley's gist.
TODO
ember-data/-private/debug
ifenvironment === "production"
? Currently the statements are always stripped.Correctly strip features which have a value other thanwill be addressed in an upcoming PRtrue
inconfig/features.json
.