Jim Lynch Codes
  • Blog
  • About Jim

Writings about one coder's stories & experiences.

Adding a "Copy Without Minification" Task to Your Gulp Build Script

6/6/2016

0 Comments

 
While working on a project for work I was presented with a plan to incorporate an animated jquery slider in our AngularJS application. I was able to wrap it in a directive and have every working honky-dory on gulp serve, but when I ran gulp build the jquery carousel widget wasn't working properly. It turned out that there were relative path references to other html, css, and JavaScript files declaring right there in the code with relative script tags. These import references were broken when the gulp build task did it's thing with minifying, uglifying, and concatenating files. Instead of going in and modifying the third party code, I was able to add these third party files into the project while keeping just these files safe from the build task. 

The Theory Behind the Solution

Basically, the build task just says here are a bunch of subtasks that, when we call the build tasks, it just runs all of these other tasks. The build task by default has three dependency tasks: 'html', 'fonts', and 'other'. These tasks do things like generate the minified and concatenated project files over to your dist/ folder. What I'm going to do is add another task to the dependencies of the build task, I'll call this one 'no-min-copy'. Then it will look in my directory for app/no-min-copy, and it will straight up copy those files (no mininification or anything) over to a 'no-min-copy' directory inside of the dist directory. Then we can keep the relative paths in our third party code and shouldn't have problems.

Updating the Code

It's not very difficult to add a new task in gulp once you understand how it works, but it can take a very long time to understand how it works. When we run gulp in the Gulp-Angular generated project it runs the gulp build task. Even at work, I normally scaffold new AngularJs projects with the Gulp-Angular yeoman generator. In the gulp folder of the scaffolding project is a file called build.js. 
gulp.task('no-min-copy', function () {
   return gulp.src([
      path.join(conf.paths.src, 'no-min/**/*.*')
   ])
     .pipe(gulp.dest(path.join(conf.paths.dist, '/no-min/')));
});
Then I'll add the no-min-copy task to the dependencies for the build task (note that in gulp 3 all the dependencies run in parallel so it doesn't matter what order you list the dependency tasks):
gulp.task('build', ['no-min-copy', 'html', 'fonts', 'other']);
0 Comments

Your comment will be posted after it is approved.


Leave a Reply.

    ​Author

    Picture
    The posts on this site are written and maintained by Jim Lynch. About Jim...
    Follow @JimLynchCodes
    Follow @JimLynchCodes

    Want FREE access to
    my daily stock tips 
    ​newsletter called,
    "The Triple Gainers"?

    Sign up here!

    Categories

    All
    Actionscript 3
    Angular
    AngularJS
    Automated Testing
    AWS Lambda
    Behavior Driven Development
    Blogging
    Business Building
    C#
    C / C++
    ClojureScript / Clojure
    Coding
    Community Service
    CS Philosophy
    Css / Scss
    Dev Ops
    Firebase
    Fitness
    Flash
    Front End
    Functional Programming
    Git
    Go Lang
    Haskell
    Illustrations
    Java
    Javascript
    Lean
    Life
    Linux
    Logic Pro
    Music
    Node.js
    Planning
    Productivity
    Professionalism
    Python
    React
    Redux / Ngrx
    Refactoring
    Reusable Components
    Rust
    Security
    Serverless
    Shell Scripting
    Swift
    Test Driven Development
    Things
    TypeScript
    Useful Sites
    Useful Tools
    Video
    Website Development
    WebStorm
    Writing

    Archives

    October 2020
    September 2020
    May 2020
    April 2020
    February 2020
    January 2020
    December 2019
    October 2019
    September 2019
    August 2019
    July 2019
    June 2019
    May 2019
    April 2019
    March 2019
    February 2019
    January 2019
    December 2018
    November 2018
    October 2018
    September 2018
    August 2018
    June 2018
    May 2018
    April 2018
    March 2018
    February 2018
    January 2018
    December 2017
    November 2017
    October 2017
    September 2017
    August 2017
    July 2017
    May 2017
    April 2017
    March 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    September 2016
    August 2016
    July 2016
    June 2016
    May 2016
    April 2016
    March 2016
    February 2016
    January 2016
    December 2015
    November 2015
    October 2015

    RSS Feed

  • Blog
  • About Jim
JimLynchCodes © 2021