Add webpack for frontend dependency loading

This commit is contained in:
Tautvidas Sipavičius
2015-08-12 14:40:57 +03:00
parent 0df8973b7e
commit c1f9fb915b
5 changed files with 85 additions and 2 deletions

View File

@ -30,6 +30,10 @@ class RoboFile extends \Robo\Tasks {
$this->_exec(join(' ', $command)); $this->_exec(join(' ', $command));
} }
function bundleJavascript() {
$this->_exec('./node_modules/webpack/bin/webpack.js');
}
function makepot() { function makepot() {
$this->_exec('grunt makepot'. $this->_exec('grunt makepot'.
' --gruntfile '.__DIR__.'/tasks/makepot/makepot.js'. ' --gruntfile '.__DIR__.'/tasks/makepot/makepot.js'.
@ -61,6 +65,11 @@ class RoboFile extends \Robo\Tasks {
$this->_exec('vendor/bin/codecept run acceptance'); $this->_exec('vendor/bin/codecept run acceptance');
} }
function testJavascript() {
// TODO: regenerate test bundle before running mocha tests
$this->_exec('./node_modules/mocha/bin/mocha -r tests/javascript/mochaTestHelper.js tests/javascript/newsletter_editor/testBundle.js');
}
function testAll() { function testAll() {
$this->_exec('vendor/bin/codecept build'); $this->_exec('vendor/bin/codecept build');
$this->loadEnv(); $this->loadEnv();

View File

@ -36,6 +36,7 @@
"sinon": "1.14.1", "sinon": "1.14.1",
"sinon-chai": "2.7.0", "sinon-chai": "2.7.0",
"stylus": "latest", "stylus": "latest",
"swag": "~0.7.0" "swag": "~0.7.0",
"webpack": "1.11.0"
} }
} }

View File

@ -0,0 +1,28 @@
var chai = require('chai');
var sinon = require('sinon');
var sinonChai = require('sinon-chai');
var chaiJq = require('chai-jq');
chai.use(sinonChai);
chai.use(chaiJq);
global.expect = chai.expect;
global.sinon = sinon;
if (!global.document || !global.window) {
var jsdom = require('jsdom').jsdom;
global.document = jsdom('<html><head><script></script></head><body></body></html>', {}, {
FetchExternalResources: ['script'],
ProcessExternalResources: ['script'],
MutationEvents: '2.0',
QuerySelector: false
});
global.window = document.parentWindow;
global.navigator = global.window.navigator;
global.window.Node.prototype.contains = function (node) {
return this.compareDocumentPosition(node) & 16;
};
}

View File

@ -31,4 +31,4 @@
)%> )%>
<!-- handlebars templates --> <!-- handlebars templates -->
<% block templates %><% endblock %> <% block templates %><% endblock %>

45
webpack.config.js Normal file
View File

@ -0,0 +1,45 @@
var path = require('path'),
fs = require('fs');
// webpack.config.js
module.exports = {
context: __dirname ,
entry: {
mailpoet: './assets/js/mailpoet',
},
output: {
path: './assets/js/src',
filename: '[name].js',
},
loaders: [
{
test: /\.js$/i,
loader: 'js'
},
{
test: /\.css$/i,
loader: 'css'
},
{
test: /\.jpe?g$|\.gif$|\.png$|\.svg$|\.woff$|\.ttf$|\.wav$|\.mp3$/i,
loader: 'file'
}
],
resolve: {
modulesDirectories: [
'node_modules',
'assets/js',
'assets/css/lib'
],
fallback: path.join(__dirname, 'node_modules'),
alias: {
'handlebars': 'handlebars/runtime.js'
}
},
resolveLoader: {
fallback: path.join(__dirname, 'node_modules'),
alias: {
'hbs': 'handlebars-loader'
}
}
};