Gulp with WebPack. Which should be building my coffee/jade etc.? - gulp

I have a pre-existing project that is currently using gulp.
The key libraries/frameworks/languages are:
MongoDB - Mongoose
AngularJS - With ui-router, also using ngClassify
ExpressJS - With Passport
NodeJS
Jade
Coffeescript
Sass - '.sass' format
JPG/PNG's
Currently everything is watched using live reload, minified using uglify and gzipped. My angular html view/directive snippets are sent into a template cache js file. Even the images are minified using image min.
The single page app is very modular by design, there are multiple 'pages' to the app, each page has a specific use (Take the profile page for example), using ui-route to nest views. Not all users will use each page. Hence why I am choosing to move towards WebPack with each 'page' being a module. The goal for this application is to be as reactive as possible. With potential mild load times when switching which page/module they are on.
My current project structure has a src and dist directory each with a server and client folder. the list directory can of course be safely deleted with every build. I currently have no raw js files or raw html (aside from the gulpfile.js that just requires my gulpfile.coffee), everything gets preprocessed by gulp and thats it.
So here are my questions:
Do I replace most of my gulpfile with webpack, and let webpack process everything (Whats the advantage of this). Or do I create an intermediary folder (The gulp output), then run webpack on that folder (just dealing with the minified js/css/html files). Basically, knowing what my libraries/frameworks are, and my situation, how would you structure the build process?
Can you use an ngClassify app.coffee file as an entry point? Or does it have to be compiled first. (If you can, how?)

You can certainly use Gulp to trigger your Webpack build and manage other tasks you may have however the idea of Webpack is that it is your entire build, you no longer need Gulp tasks to 'minify, 'concatenate' and 'imagemin' files etc as Webpack does all this for you by using Plugins and Loaders.
You will have to run Webpack on the project source, not an already minified bundle created by your custom Gulp build.
The angular questions I don't have an answer to I'm afraid :)

Related

Webpack scan html templates for assets and process them

In my project I use Webpack mainly for bundling .js and .css files.
Main question is about images. When images are used in .css files Webpack process them and exports to /dist folder. Which is fine, and works like a charm.
What I want to accomplish is pretty same story but with .html files. But! Html files are in different location then my wepack-app.
-/root
--/design
-----/src
--------/js
--------/css
--------/images
--------/...
-----/dist
--/templates
--/...
Is it possible to e.g pass additional path to scan for assets?
I don't want to produce new html. Just check which assets are used in html files from root/design/src/images then process them (same as from css files) and copy to /dist.
You can add a new entry point (a js file) that will require all the html files that you want to be processed.
You will need to install html-loader in order to allow webpack to "understand" html files.

Polymer build compress

I am generating a component application in Polymer .. as a template I used the following: https://github.com/PolymerLabs/start-polymer3. Everything works excellent, I uploaded it to firebase, the point is that I want to make 'polymer build' generate the structure of folders: build / s6-unbundled, along with other folders like node_modules and my custom script, if you know some way to compress all the scripts generated in the build into a single file. Since the components I want to insert in third-party sites but I want to load only one js file and not have to load all what the polymer generates. I've done this with vue-custom.component but I do not know how to Polymer. I appreciate your help.

How to enable autominify of .js and .css files in PHP storm 10.0.3?

I want to see CSS and JS files normaly when editing them. But when I save/upload them to server I want them to be minified. Is there a plugin/setting that does this in the current version of PHPstorm?
PHPStorm doesn't have any built-in functions for minifying files... But there are plenty of different tools on the web - plus you can create your own batch files for this.
I can suggest using Grunt grunt-contrib-uglify and grunt-contrib-cssmin tasks, for example . Both tasks support merging and minifying files. You can run the tasks using Grunt console. Or, you can use YUI Compressor and set it up as a file watcher (https://www.jetbrains.com/webstorm/help/minifying-javascript.html, https://www.jetbrains.com/webstorm/help/minifying-css.html)
You can add css, or js File Watcher in PhpStorm, see their docs, using uglify or yuicompressor. All configurable from the IDE
After proper setup, your .css and .js files will be minified locally( PhpStorm shows them nicely together in the left sidebar where your files are). Each time you change your original css or js file, minified versions will be autogenerated.
When uploading to the server, you just need to upload automatically minified versions.
Very convenient. I use it for non-Symfony projects ( in symfony i use assetic for minification and combining assets into one file)

Why is Polymer just a series of HTML files with JavaScript?

I'm starting to experiment with Polymer 1.0, and I noticed that the some of files included via Bower are broken up into the following three:
polymer-micro.html
polymer-mini.html
polymer.html
And each file is imported via HTML Imports within the next one down the list. Then, the rest of the file is just JavaScript.
Perhaps, it's my lack of knowledge regarding HTML Imports, but is this a clever way to utilize dependency management for JavaScript without having to add a third-party library like Browserify for example?

Bower and Grunt workflow

I just want to get an opinion on my workflow. I am aware of Yeoman and have on purpose decided not to use it. My workflow goes like this:
Run bower install to install all project assets dependencies.
Run grunt which copies all js files from the bower components folder to a new js folder and all css files to a new css folder.
Further use grunt task to concatenate and minify all js and css files from the new folders and put them in a dist folder.
Refer to the final minified css and js in dist folder from HTML.
One thing i certainly don't want to do in my grunt task is to perform dependency specific task e.g. grab all js file from bootstrap folder into the new js folder, then grab all js file from prettyphoto folder into the new js folder. I want the grunt task to be as generic as possible so that i can use the same gruntfile in any project no matter what the bower dependencies might look like. The reason is if i should spend all those time writing my gruntfile for each project, why would i not just grab the source codes for all the dependencies in conventional way.
So there is a grunt-contrib-copy plugin to copy files from one place to another which i use to grab all js files from inside the bower's components folder. The problem is most of the bower components come with regular js and minified version of it. So, i am copying both of them and concatenating and uglifying them. So duplicate code!
Does my workflow makes sense? Is so, how can I get rid of the problem I mentioned in the paragraph above?
If I'm understanding correctly, you should take a look at grunt-usemin. You can wrap your js tags in <!-- build:js js/foo.js -->. The useminPrepare task that's included in the package will cycle through any scripts (or css, or images, etc.) that are there and dynamically add them to the concat or uglify task.
The one downside I've found is that the usemin task is fairly slow but hopefully if this pull request is implemented, things will get much, much faster.