I am into building functional prototypes, but also for outputting CSS and JS, which means we have 2 times we build out our code, once as a demo with HTML files (we are using assemble.io) and another, where we are building out the files to be uploaded to production (an Enterprise CMS).
Most things about the build are the same, but the main difference is certain paths within the CSS need to change. I have set up a sass variable, and when building, I change it and then change it back when I'm done (I do it in place, because other tasks are moving the sass files around.)
The problem is this method just feels really wonky, and not at all extensible.
We are using a gruntfile that is mostly the same as the one provided with the yeoman webapp generator, with some of our specific tasks added for good measure.
Here are excerpts of the relevant sections of my Gruntfile:
grunt.initConfig({
//...
// Copies remaining files to places other tasks can use
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: '<%= config.app %>',
dest: '<%= config.dist %>',
src: [
'*.{ico,png,txt}',
'images/{,*/}*.webp',
'{,*/}*.html',
'fonts/{,*/}*.*',
'styles/fonts/{,*/}*.*'
]
}, {
src: 'node_modules/apache-server-configs/dist/.htaccess',
dest: '<%= config.dist %>/.htaccess'
}, {
expand: true,
dot: true,
cwd: '<%= config.app %>/components/bootstrap-sass-official/assets/fonts/bootstrap',
src: '*',
dest: '<%= config.dist %>/fonts'
}, {
expand: true,
dot: true,
cwd: '<%= config.app %>/components/font-awesome/fonts/',
src: '*',
dest: '<%= config.dist %>/fonts'
}]
},
styles: {
expand: true,
dot: true,
cwd: '<%= config.app %>/styles',
dest: '.tmp/styles/',
src: '{,*/}*.css'
}
},
// Run some tasks in parallel to speed up build process
concurrent: {
server: [
'sass:server',
'assemble'
],
test: [
'copy:styles'
],
dist: [
'sass',
'copy:styles',
'assemble',
'imagemin',
'svgmin'
]
},
replace: {
prodSass: {
src: ['<%= config.app %>/styles/utils/_variables.scss'],
overwrite: true,
replacements: [
{
from: '$site-root: $build-root',
to: '$site-root: $prod-root'
}
]
},
prodSassRevert: {
src: ['<%= config.app %>/styles/utils/_variables.scss'],
overwrite: true,
replacements: [
{
from: '$site-root: $prod-root',
to: '$site-root: $build-root'
}
]
}
}
//..
});
grunt.registerTask(
'build',
'Build out the codez! takes an optional `env` parameter so we can build in different ways',
function(env){
grunt.task.run(
'clean:dist',
'handlebars',
'assemble',
'wiredep'
);
// if 'prod' environment we need to do some variable modification
// before the sass is compiled (which happens in 'concurrent')
if (env === 'prod'){
grunt.task.run('replace:prodSass');
}
grunt.task.run(
'concurrent:dist',
'preprocess:html',
'useminPrepare',
'autoprefixer',
'concat',
'cssmin',
'pixrem:dist',
'uglify',
'copy:dist',
'modernizr',
'usemin'
);
if (env === 'prod'){
grunt.task.run('replace:prodSassRevert');
}
}
);