Skip to content

Instantly share code, notes, and snippets.

@SalahAdDin
Created April 26, 2016 01:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SalahAdDin/34c239544823701aaa57e937ee781aec to your computer and use it in GitHub Desktop.
Save SalahAdDin/34c239544823701aaa57e937ee781aec to your computer and use it in GitHub Desktop.
Django jet statics compiler config.
var fs = require('fs');
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var COMMON_SCSS_PATH = './scss';
var COMMON_CSS_PATH = './css';
/*
function fileList(dir) {
return fs.readdirSync(dir).reduce(function(list, file) {
var name = path.join(dir, file);
var isDir = fs.statSync(name).isDirectory();
return list.concat(isDir ? fileList(name) : [name]);
}, []);
}
*/
// Trivial to extend with `includeDirs`, just follow same pattern
function fileList(dir, excludeDirs?) {
return fs.readdirSync(dir).reduce(function (list, file) {
const name = path.join(dir, file);
if (fs.statSync(name).isDirectory()) {
if (excludeDirs && excludeDirs.length) {
excludeDirs = excludeDirs.map(d => path.normalize(d));
const idx = name.indexOf(path.sep);
const directory = name.slice(0, idx === -1 ? name.length : idx);
if (excludeDirs.indexOf(directory) !== -1)
return list;
}
return list.concat(fileList(name, excludeDirs));
}
return list.concat([name]);
}, []);
}
function Theme(dir){
this.dir = dir; // Theme's directory
this.sourceFiles = path.join('.', COMMON_SCSS_PATH, this.dir); // Source files path
}
Theme.prototype = Object.create(null);
Theme.prototype.scssIncludePaths = function() {
return [this.sourceFiles];
};
Theme.prototype.scssSources = function() {
return path.join(this.sourceFiles, '/scss/**/*.scss');
};
var themes = [
new Theme('themes/default'),
new Theme('themes/green'),
new Theme('themes/light-blue'),
new Theme('themes/light-gray'),
new Theme('themes/light-green'),
new Theme('themes/light-violet')
];
var flatten = function(arrOfArr) {
return arrOfArr.reduce(function(flat, more) {
return flat.concat(more);
}, []);
};
/*
var includePaths = flatten(themes.map(function(app) { return app.scssIncludePaths(); }));
Error, includePaths can't be this
*/
var sources = flatten(themes.map(function(app) { return app.scssSources(); }));
var includePaths = flatten(themes.map(function(app) { return app.scssIncludePaths(); }));
// var includePaths = fileList(COMMON_SCSS_PATH, ['themes']);
// var results = path.join('./', includePaths);
// process.stdout.write("Include paths: "+includePaths+"\n");
process.stdout.write("Sources: "+sources+"\n");
// process.stdout.write("Results: "+results);
module.exports = function exports() {
// var includePaths = flatten(themes.map(function(app) { return app.scssIncludePaths(); }));
var sources = flatten(themes.map(function(app) { return app.scssSources(); }));
// var results = path.join('css/', sources);
process.stdout.write("Include paths: " + includePaths);
process.stdout.write("Sources: "+sources);
process.stdout.write("Results: "+results);
return {
entry: [
COMMON_SCSS_PATH,
'scss/**.scss',
'scss/select2/',
'scss/jquery-ui/',
'scss/icons/',
// includePaths,
sources
],
devtool: "source-map",
output: {
path: 'css/',
publicPath: sources,
filename: '[name].css',
},
module: {
loaders: [
{
test: /\.scss$/,
loaders: ["style", "css?sourceMap", "sass?sourceMap"]
},
{
test: /\.css$/,
loader: "style-loader!css-loader!postcss-loader"
}
]
},
postcss: [ autoprefixer({ browsers: ['last 2 versions'] }) ]
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment