6

I'm using Grunt to build the Durandal starter kit pro package.

It all works fine, except for one tiny detail. I would like to exclude one file (app-config below) from the optimizer and keep it as a non minified file when my build is done.

Based on other SO thread suggestions, I'm currently excluding it using empty:, which removes it from the optimized file as expected. However, when I open the built project I get an error in the console:

Uncaught Error: main missing app-config

options: {
    name: '../lib/require/almond-custom',
    baseUrl: requireConfig.baseUrl,
    mainPath: 'app/main',
    paths: mixIn({ }, requireConfig.paths, { 
         'almond': 'lib/require/almond-custom', 
         'app-config': 'empty:' 
    }),
    optimize: 'none',
    out: 'build/app/main.js',
    preserveLicenseComments: false
}

Is almond the problem? I tried switching it to the full requirejs using include: ['path/to/require'], without success.

If you want to reproduce it locally you can either download the starter kit from the above link, or use a slightly configurated version which is closer to my example. Just run an npm install in the folder and you're all set.

Johan
  • 35,120
  • 54
  • 178
  • 293
  • So, I'm _sure_ you've already looked at this, and I'm not even really familiar with durandal, but on the [github page](https://github.com/RainerAtSpirit/HTMLStarterKitPro), in the `options` object, they show a property called `exclude` that accepts an array... – Alexander Nied Oct 10 '16 at 01:17
  • @anied Thanks for the tip. Yes, I have tried both `empty:` and the exclude property, both resulting in the same exception. – Johan Oct 10 '16 at 08:33

3 Answers3

3

I have downloaded you source code and do the following steps.

  1. Extract zip file, open cmd and change the directory to this folder.
  2. Run npm install to install all the dependencies.
  3. Run grunt to start to build the project.

And when I open http://localhost:8999/ and saw the alert 1 which is alert(appConfig.foo); in your main.js. After clicked Ok to hide the alert, the web page works fines. Any more input for you ?

First step

Second step

So I am not sure how you are facing with this issue.

trungk18
  • 19,744
  • 8
  • 48
  • 83
  • It's important that you run the `grunt build` task and not the default `grunt` task to try the build :) Sorry about not mentioning that. – Johan Oct 10 '16 at 08:31
  • I saw it problem, but haven't seen any wrong here. If I remove completely app-config on your paths definition and passing into define as '../app-config.js', It works fine but the app-config.js is included in the main.js. Let me think a bit more. I have no idea what is Almond but you might wish to see this question. http://stackoverflow.com/questions/15515872/inline-require-working-in-requirejs-but-not-with-optimized-almond-build – trungk18 Oct 10 '16 at 09:47
  • If almond is the problem it's possible to use requirejs instead. It's included in the `lib` folder too... – Johan Oct 10 '16 at 11:06
  • Just guessing since I haven't' used it before. – trungk18 Oct 10 '16 at 11:08
0

From the reference of the durandal issues found in this particular link grunt-durandal

The main module controls the implementation of the durandal services The link can be found in main.js

Here you can see the system.debug(true).You can remove it as written in the post here document.

The function as quoted in the article Overrides request execution timeout making it effectively infinite.

Also while using uglify in grunt the debug is set to false as per the documentation.

As per the documentation you need to set the system.debug(false)

Hope this might help a bit.

Pritish Vaidya
  • 21,561
  • 3
  • 58
  • 76
0

try:

....
paths: mixIn({ }, requireConfig.paths, { 
     'almond': ['lib/require/almond-custom', '!lib/require/almond-custom/app-config.js']
}),
....

just note the second path of app-config.js is correct. I think you should find your way, the above is a hint, if not a direct solution.

T.Todua
  • 53,146
  • 19
  • 236
  • 237