Skip to content
This repository has been archived by the owner on Apr 24, 2024. It is now read-only.

Commit

Permalink
Adds webpack for the js
Browse files Browse the repository at this point in the history
  • Loading branch information
lejoe committed Nov 25, 2015
1 parent 9c61ea8 commit 2abf10d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
4 changes: 2 additions & 2 deletions gulp/config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
'use strict';
var argv = require('yargs').argv;
var path = require('path');

module.exports = function () {

var basePaths = {
root: path.join(__dirname, '..'),
src: 'src/',
content: 'content/',
assets: 'assets/',
Expand Down Expand Up @@ -83,8 +85,6 @@ module.exports = function () {
}
};



return {
basePaths: basePaths,
languages: languages,
Expand Down
37 changes: 34 additions & 3 deletions gulp/tasks/scripts.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
'use strict';
var stream = require('../utils/browserSync').stream;
var stream = require('../utils/browserSync').stream;
var webpack = require('webpack');
var gulpWebpack = require('webpack-stream');
var glob = require('glob');

module.exports = function (gulp, $, config) {
var srcFiles = config.appFiles.scripts;
var tasksHelper = require('../utils/tasksHelpers')(gulp, config);
var scriptsFiles = config.appFiles.scripts;
var srcFiles = glob.sync(scriptsFiles);
var destPath = config.paths.scripts.dest;
var skeletonRoot = config.basePaths.root;
var srcRoot = config.basePaths.src;

var task = function () {
return gulp.src(srcFiles)
return gulp.src(scriptsFiles)
.pipe($.eslint({envs: ['browser']}))
.pipe($.eslint.format())
.pipe(gulpWebpack({
debug: true, //TODO improve this one we have env depending builds
entry: {
main: srcFiles,
// Add modules you want to load from vendors here so they are put in a seperate file
vendor: ['jquery']
},
output: {
filename: 'main.js'
},
loaders: [
{ test: /\.js$/, loader: 'babel?presets[]=es2015', exclude: /node_modules/}
],
resolve: {
// Makes sure the paths are relative to the root and not this file
root: skeletonRoot,
// Makes sure the compiler looks for modules in /src and node_modules
modulesDirectories: [srcRoot, 'node_modules']
},
plugins: [
// Makes sure the vendors are only imported once in this seperate file
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.min.js')
]
}))
.pipe(gulp.dest(destPath))
.pipe(stream());
};
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
"sensible": "0.5.4"
},
"devDependencies": {
"babel-core": "^6.2.1",
"babel-loader": "^6.2.0",
"babel-preset-es2015": "^6.1.18",
"browser-sync": "^2.6.5",
"del": "^1.1.1",
"gulp": "git://github.com/gulpjs/gulp.git#4.0",
Expand Down Expand Up @@ -43,6 +46,8 @@
"merge-stream": "^0.1.7",
"rsyncwrapper": "^0.4.2",
"run-sequence": "^1.1.0",
"webpack": "^1.12.8",
"webpack-stream": "^2.1.1",
"yamljs": "^0.2.1",
"yargs": "^3.9.1"
}
Expand Down
1 change: 1 addition & 0 deletions src/layouts/default.jade
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ html(lang=language)
body
block body

script(src='#{relativePath}/js/vendor.min.js')
script(src='#{relativePath}/js/main.js')


Expand Down
10 changes: 9 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
'use strict';

// This is how you require your component script:
require('elements/header/script');

// This is how you require a component from node_modules
// Make sure to add it to the vendors in /gulp/tasks/scripts
var $ = require('jquery');

var document, window;
(function(){
// TODO: add your JS here
}(document, window));
}(document, window, $));

0 comments on commit 2abf10d

Please sign in to comment.