0

I'm using gulp-usemin to combine my JS files (with uglify)

I have a folder structure as follows:

Top
  |- Web
      |- Scripts
         |- App
             |- script1.js
             |- script2.js
         |- Vendor (folder)
         |- CompiledScripts
             |- useminFile1.js
      |- Areas
          |- Area1
              |- index.html

All the usecases for gulp-usemin designate copying everything to a dist folder, which I cannot do.

The goal is to rewrite the index.html file to it's current location, but to write the combined JS files to 'Top/Web/Scripts/CompiledScripts'. I've tried various combinations but I can only get JS OR html in the correct place, never both.

I've put the basic task below. This will output the re-written index file in the correct location, but not the compiled JS files (will be in same directory as the html file, put at the path in the html block).

gulp.src('./Top/Web/Areas/Area1/index.html')
    .pipe(usemin({
        path: './Top/Web/',
        assetsDir: './Top/Web/',
        js: [
            uglify()
        ]
    }))
    .pipe( gulp.dest( './Top/Web/Areas/Area1/' ) );

HTML Block. Needs to have absolute path to scripts

<!-- build:js /Scripts/CompiledModules/Libraries/test.js -->
    <script src="/Scripts/Vendor/Bower/lodash/dist/lodash.js"></script>
    <script src="/Scripts/Vendor/Bower/jquery/jquery.js"></script>
<!-- endbuild -->

Any help would be greatly appreciated. Trying more combinations as we speak

vernak2539
  • 574
  • 3
  • 14

1 Answers1

0

Since you have:

.pipe( gulp.dest( './Top/Web/Areas/Area1/' ) );

You need to use:

<!-- build:js ../../Scripts/CompiledScripts/vendor.min.js -->
am_
  • 2,378
  • 1
  • 21
  • 28
  • That seemed to accomplish a little bit of my problem. Now i'll just pump the index files through to remove the relative path. Thanks – vernak2539 Mar 09 '15 at 11:26
  • Np. Be aware that there's a couple of bugs for usemin that might confuse you when trying to set this up. (look at github repo). I ended up using useref instead, and it works great together with gulp-if. – am_ Mar 09 '15 at 11:32
  • Thanks. Yeah, I'll be looking into that as I have multiple blocks in the same file. – vernak2539 Mar 09 '15 at 11:43