Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-2478] Tooling: Allow Excluding JS files from Compilation

GitHub Issuen/a
TypeNew Feature
PriorityHigh
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsTooling
Labelscb-tooling, dr-list, parity
ReporterDon Thorp
AssigneeChris Barber
Created2011-04-15T03:20:50.000+0000
Updated2017-11-10T15:27:53.000+0000

Description

Please create an implementation ticket for each platform once the feature has been designed. It is sometimes desirable to exclude local javascript files from compilation as Titanium javascript. The best use case is wanting to include a JS file in a WebView's html. See [Helpdesk 56271](http://developer.appcelerator.com/helpdesk/view/56271)

Comments

  1. Don Thorp 2011-04-15

    To work around this problem simply rename your .js files that you don't want processed to something like .jslocal.

  2. Paul Dowsett 2011-10-06

    The problem here is that local js libraries, such as those used with webviews, are being modified during the build process, which causes them not to work when the app is launched. While Don's suggestion to use .jslocal is a good idea, it doesn't work for multi-file libraries, as they cannot be simply dropped into the project. Thus, all the library's files would need to be renamed. This is causing our team a particular problem because we want to create video tutorials relating to including local js libraries but, as it stands, these will only serve to emphasize the issue. Also, as soon as the ticket is resolved, the tutorials will be outdated. TonyL's suggestion, which seems viable, is for there to be a directory like /local that is always excluded from the build process, and the files that it contains copied over verbatim to the packaged app.
  3. Tony Lukasavage 2011-10-06

    What he said ^^
  4. Jose Angel Rufino Baquero 2014-03-05

    My problem was that I can't use a different name for those local .js files because it's being used by a compiled iOS library which I have to use in a Titanium iOS module, in order to use it in my app. Such library was looking for .js files in the resources folder and crashing when were not found. I solved it adding a cli hook:
       cli.addHook('build.post.compile', function (build, finished) {
               // "build" arg contains the state of the build
        
               //projectDir /Users/Jose/Documents/Titanium_Studio_Workspace/Project
               //buildDir:/Users/Jose/Documents/Titanium_Studio_Workspace/Project/build/iphone
               
               // xcodeAppDir /Users/Jose/Documents/Titanium_Studio_Workspace/Project/build/iphone/build/Debug-iphonesimulator/project.app
               // Problematic file => /Users/Jose/Documents/Titanium_Studio_Workspace/Project/build/iphone/build/Debug-iphonesimulator/project.app/NATIVE_SDK_BUNDLE.bundle/jsresource.js
       
       		if(build.platformName == "iphone"){
              		logger.log("======= ADDING LOCAL JS FILES FOR WEBVIEWS =======");
               
       	        var originalResource = build.projectDir+"/app/assets/iphone/NATIVE_SDK_BUNDLE.bundle/jsresource.js";
       	        var originalResource2 = build.projectDir+"/app/assets/iphone/NATIVE_SDK_BUNDLE.bundle/jsresource2.js";
       	        
       	        logger.log(originalResource);
       	        logger.log(originalResource2);
       	        
       	        var destResource = build.xcodeAppDir+"/ORMMAResourceBundle.bundle/jsresource.js";
       	        var destResource2 = build.xcodeAppDir+"/ORMMAResourceBundle.bundle/jsresource2.js";
       	        
       	        var fs = require('fs');
       			fs.writeFileSync(destResource, fs.readFileSync(originalResource));
       			fs.writeFileSync(destResource2, fs.readFileSync(originalResource2));
              
       		}
       		
       		finished();
           });
       
  5. Ingo Muschenetz 2014-03-05

    Very nice!
  6. luca capra 2014-09-19

    Something working as a .gitignore file for Titanium, a .tignore file
  7. Christian Green 2016-03-28

    This feature is sorely needed. Have there been any work arounds discovered other than renaming the file extension?
  8. Chris Barber 2016-03-28

    [~christian.j.green@gmail.com] One thing you can do that will work is put the JS files you don't want minified/encrypted into the platform directory. Assuming the latest Titanium SDK 5.2.1:
       

    iOS Simulator builds

    <project-dir>/platform/ios/build/Products/Debug-iphonesimulator/<appname>.app

    iOS Device builds

    <project-dir>/platform/ios/build/Products/Debug-iphoneos/<appname>.app

    iOS Dist adhoc and appstore builds

    <project-dir>/platform/ios/build/Products/Release-iphoneos/<appname>.app

    Android builds (emulator, device, dist-playstore)

    <project-dir>/platform/android/bin/assets/Resources

    Mobile Web

    <project-dir>/platform/mobileweb
  9. Christian Green 2016-03-28

    [~cbarber] Currently the files are under /modules/android//res/raw as it is a third party module. Will your suggested fix work for this format? Thanks!
  10. Chris Barber 2016-03-28

    [~christian.j.green@gmail.com] Actually, I have to take it all back. I just noticed in the code that we treat all files in the platform/android directory the same as the Resources directory. If you look at https://github.com/appcelerator/titanium_mobile/blob/master/android/cli/commands/_build.js#L2495-L2511 you'll see line 2505 calls copyDir just the same as Resources on line 2438 and line 2450. This means that all JS files in the platform directory would be minified and encrypted too. We probably shouldn't be doing that to files in the platform directory.
  11. Christian Green 2016-03-28

    [~cbarber] Would it be possible to hook into the command line during build and work with the cli.ignoreFiles config property?
  12. Chris Barber 2016-03-28

    No, I don't think so. You could write a hook that moves all the JS files out of the project during pre-compile, then moves them back in during post-compile while also copying them to the compiled app output directory build/android/bin/assets/Resources. Or, you could just edit the android/cli/commands/_build.js in your local Titanium SDK and just hack something in. That's probably the easiest solution, though you'll have to re-add your hack if you change the SDK you want to use.
  13. Matt Mendick 2017-11-10

    This was a breaking issue for us and so an official .tiignore file of some sort would be welcomed. We have a project which uses a large number of web resources that we copy in from another source project. Our workaround is similar to Chris's suggestion in that it deals with writing a hook. We have a build.pre.compile plugin hook which already does a lot of work copying over our files from the other project into this project, and so we added a step to create a dummy.html file containing