简体   繁体   中英

Output JS and HTML to different locations using Gulp Usemin

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

Since you have:

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

You need to use:

<!-- build:js ../../Scripts/CompiledScripts/vendor.min.js -->

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM