Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJonathan Ankiewicz
17,901 PointsHow do I stop NPM from dropping unused functions and variables?
How do I ensure NPM stops from dropping unused functions and variables?
4 Answers
Jonathan Ankiewicz
17,901 PointsNo, when running the uglify task, Uglify responded with completed but we drop these variable and functions because they are unused.
It dropped a function that was being called else where and had no reference too, on the pages in the folder, but will be added at a later time. So I wanted to know how I can get NPM to not removed unused functions or variables.
I did look closer and realized most of what it removed was good, because I missed the fact it wasn't needed. But there was one function I still wanted to keep.
Tom Geraghty
24,174 PointsThat's kind of the whole point of doing these tasks: getting your code ready for production/build environment.
Why are you keeping a function that doesn't ever get called? If it's not yet used by your application then uglifyjs is supposed to remove it to reduce filesize. If you want to keep that function around for developing it later into something that will be called/used, then keep it in development only.
Check out the API https://github.com/mishoo/UglifyJS. There's a chance that the --reserved-names
flag might accomplish what you are asking.
You could also cheat and call the function you want to keep somewhere in the code such as:
function keepThisFunction() { return 'foo'; }
const throwaway = keepThisFunction();
But this seems hacky and to run counter to the point of using these build tasks.
Nurul Ahsan
2,039 PointsI think, you can make it ready but don't call the function then your function will not work, when it need to activate then call the function.
Nurul Ahsan
2,039 PointsI am not clear. Would u pls question make it clear. Do u like to drop ur unused function or document, if so pls put //before your unused word.