- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I want to remove all my debug code and comments before launching. Maybe also sort versions and different platforms. Is there a preprocessor #ifdef function implemented in xdk or JS, Html, Less? Or is there another way I can do this?
Any experiences?
Thanks
- Tags:
- HTML5
- Intel® XDK
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unfortunately JS has no preprocessor functionality. I's not a compiled language live Java or C# and XDK doesn't do anything with your JS files.
There are a few external options: http://stackoverflow.com/questions/7376131/ifndef-in-javascript
(and maybe more...)
In our project we use a global variable: debugMode and use it in our JS code, but that doesn't work for comments....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your answer. I hope XDK will implement such a function. I would make the apps smaller and faster. I think this would be very welcome by the community.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess it has to be made like special comments otherwise jslint etc would not work.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
While JS does not itself support pre-processing, there are lots of preprocessing tools that can remove debug code, comments, etc. Checkout UglifyJS, Browserify, Sweet.js and Google "Javascript minification". You'll probably also encounter Grunt and Gulp.
One or more of these tools will do what you need. Sweet.js is the most powerful, and is probably way more than you need, and difficult. UglifyJS is straightforward and very popular.
Good luck,
Chris
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Chris this is really helpful,
I looked at UglifyJS and the dead_code flag will do the job.
How do I do this in XDK? My intuitive idea is to make a script that runs UglifyJS and saves the output in a parallel project. Then I test the parallel project. Is this the way?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
We don't have a good way to do it automatically for you, something like what you are describing could work. There has been talk of adding some scripts directories as part of the project that could be used for such tasks, but that has only been discussion, no commitment at this point.
One guy described in another thread that he keeps two source directories in the project, for example: "dev" and "www" He does his main work in "dev" and then runs scripts that convert and copy his files for production into the "www" directory. He has to change the "source directory" option on the Projects tab to switch between the two setups. See this image for a location of the option that allows you to switch the tag. You have to push the folder icon to make the change.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page