Skip to content

Commit

Permalink
Move static assets managed by Gulp to make Django happier
Browse files Browse the repository at this point in the history
  • Loading branch information
lmorchard committed Aug 18, 2015
1 parent fb518ad commit 179e421
Show file tree
Hide file tree
Showing 17 changed files with 34 additions and 25 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ MANIFEST
.coverage
node_modules/
static/
static-src/vendor/
client-build/
client-src/vendor/
venv/
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
53 changes: 29 additions & 24 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const connect = require('gulp-connect');

const IS_DEBUG = true;

const SRC_PATH = './client-src/';
const DEST_PATH = './client-build/';

// Lint the gulpfile
gulp.task('selfie', function selfieTask() {
return gulp.src('gulpfile.js')
Expand All @@ -29,38 +32,48 @@ gulp.task('selfie', function selfieTask() {

// Lint the *.js files
gulp.task('lint', function lintTask() {
return gulp.src(['*.js', 'static-src/scripts/**/*.js'])
return gulp.src(['*.js', SRC_PATH + 'scripts/**/*.js'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failOnError());
});

gulp.task('clean', function cleanTask(done) {
del([
'static'
DEST_PATH
], done);
});

gulp.task('npm:tabzilla:img', function npmTabzillaImgTask() {
return gulp.src('node_modules/mozilla-tabzilla/media/**')
.pipe(gulp.dest('static/vendor/mozilla-tabzilla/media'));
.pipe(gulp.dest(DEST_PATH + 'vendor/mozilla-tabzilla/media'));
});

// Copy the tabzilla assets into the src dir for inclusion in minimization
gulp.task('npm:tabzilla:css', function npmTabzillaCssTask() {
return gulp.src('./node_modules/mozilla-tabzilla/css/tabzilla.css')
.pipe(rename('mozilla-tabzilla/css/tabzilla.scss'))
.pipe(gulp.dest('./static-src/vendor'));
.pipe(gulp.dest(SRC_PATH + 'vendor'));
});

// Copy the normalize assets into the src dir for inclusion in minimization
gulp.task('npm:normalize', function npmNormalizeTask() {
return gulp.src('./node_modules/normalize.css/normalize.css')
.pipe(rename('normalize.css/normalize.scss'))
.pipe(gulp.dest('./static-src/vendor'));
.pipe(gulp.dest(SRC_PATH + 'vendor'));
});

gulp.task('vendor', function vendorTask(done) {
return runSequence([
'npm:tabzilla:img',
'npm:tabzilla:css',
'npm:normalize'
], done);
});

// Scripts
gulp.task('scripts', function scriptsTask() {
const b = browserify('./static-src/scripts/main.js', {
const b = browserify(SRC_PATH + 'scripts/main.js', {
debug: IS_DEBUG
});

Expand All @@ -73,33 +86,25 @@ gulp.task('scripts', function scriptsTask() {
.pipe(uglify())
.on('error', gutil.log)
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest('./static/scripts'));
.pipe(gulp.dest(DEST_PATH + 'scripts'));
});

// Styles
gulp.task('styles', function stylesTask() {
return gulp.src('./static-src/styles/main.scss')
return gulp.src(SRC_PATH + 'styles/main.scss')
.pipe(sass().on('error', sass.logError))
.pipe(autoprefixer('last 2 version'))
.pipe(gulp.dest('static/styles'))
.pipe(gulp.dest(DEST_PATH + 'styles'))
.pipe(rename({ suffix: '.min' }))
.pipe(minifycss())
.pipe(gulp.dest('static/styles'));
.pipe(gulp.dest(DEST_PATH + 'styles'));
});

// Images
gulp.task('images', function imagesTask() {
return gulp.src('./static-src/images/**/*')
return gulp.src(SRC_PATH + 'images/**/*')
.pipe(cache(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true })))
.pipe(gulp.dest('static/images'));
});

gulp.task('vendor', function vendorTask(done) {
return runSequence([
'npm:tabzilla:img',
'npm:tabzilla:css',
'npm:normalize'
], done);
.pipe(gulp.dest(DEST_PATH + 'images'));
});

gulp.task('build', function buildTask(done) {
Expand All @@ -115,15 +120,15 @@ gulp.task('build', function buildTask(done) {

// Watches the things
gulp.task('watch', ['build'], function watchTask () {
gulp.watch('static-src/styles/**/*', ['styles']);
gulp.watch('static-src/images/**/*', ['images']);
gulp.watch('static-src/scripts/**/*', ['scripts']);
gulp.watch(SRC_PATH + 'styles/**/*', ['styles']);
gulp.watch(SRC_PATH + 'images/**/*', ['images']);
gulp.watch(SRC_PATH + 'scripts/**/*', ['scripts']);
});

// Set up a webserver for the static assets
gulp.task('connect', function connectTask () {
connect.server({
root: 'static',
root: DEST_PATH,
livereload: false,
port: 9988
});
Expand Down
3 changes: 3 additions & 0 deletions idea_town/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@

STATIC_ROOT = config('STATIC_ROOT', default=os.path.join(BASE_DIR, 'static'))
STATIC_URL = config('STATIC_URL', '/static/')
STATICFILES_DIRS = [
'client-build', # Managed by gulpfile.js
]
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'

MEDIA_ROOT = config('MEDIA_ROOT', default=os.path.join(BASE_DIR, 'media'))
Expand Down

0 comments on commit 179e421

Please sign in to comment.