Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webpack dev server #251

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,5 @@
<app>
Loading...
</app>

<!-- Google Analytics: change UA-71073175-2 to be your site's ID -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-71073175-2', 'auto');
ga('send', 'pageview');
</script>
</body>
</html>
6 changes: 6 additions & 0 deletions config/jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

const angular = require('angular');
Object.defineProperty(window, 'angular', { value: angular });

require('angular-mocks');
require('../client/app/app.js');
15 changes: 12 additions & 3 deletions webpack.dev.config.js → config/webpack.dev.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
var webpack = require('webpack');
var path = require('path');
var config = require('./webpack.config');
var config = require('../webpack.config');

config.mode = 'development';
config.output = {
filename: '[name].bundle.js',
publicPath: '/',
path: path.resolve(__dirname, 'client')
path: path.resolve(__dirname, '..', 'client')
};

config.devServer = {
port: 3000,
contentBase: '../client',
hot: true,
stats: { colors: true },
inline: true,
historyApiFallback: true
};

config.plugins = config.plugins.concat([
Expand Down
5 changes: 3 additions & 2 deletions webpack.dist.config.js → config/webpack.prod.config.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
var webpack = require('webpack');
var path = require('path');
var config = require('./webpack.config');
var config = require('../webpack.config');

config.mode = 'production';
config.output = {
filename: '[name].bundle.js',
publicPath: '',
path: path.resolve(__dirname, 'dist')
path: path.resolve(__dirname, '..', 'dist')
};

config.plugins = config.plugins.concat([
Expand Down
93 changes: 2 additions & 91 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,19 @@
import gulp from 'gulp';
import webpack from 'webpack';
import path from 'path';
import sync from 'run-sequence';
import rename from 'gulp-rename';
import template from 'gulp-template';
import fs from 'fs';
import yargs from 'yargs';
import lodash from 'lodash';
import gutil from 'gulp-util';
import serve from 'browser-sync';
import del from 'del';
import webpackDevMiddleware from 'webpack-dev-middleware';
import webpackHotMiddleware from 'webpack-hot-middleware';
import colorsSupported from 'supports-color';
import historyApiFallback from 'connect-history-api-fallback';

let root = 'client';

// helper method for resolving paths
let resolveToApp = (glob = '') => {
return path.join(root, 'app', glob); // app/{glob}
};

let resolveToComponents = (glob = '') => {
return path.join(root, 'app/components', glob); // app/components/{glob}
};

// map of all paths
let paths = {
js: resolveToComponents('**/*!(.spec.js).js'), // exclude spec files
scss: resolveToApp('**/*.scss'), // stylesheets
html: [
resolveToApp('**/*.html'),
path.join(root, 'index.html')
],
entry: [
'babel-polyfill',
path.join(__dirname, root, 'app/app.js')
],
output: root,
blankTemplates: path.join(__dirname, 'generator', 'component/**/*.**'),
dest: path.join(__dirname, 'dist')
};

// use webpack.config.js to build modules
gulp.task('webpack', ['clean'], (cb) => {
const config = require('./webpack.dist.config');
config.entry.app = paths.entry;

webpack(config, (err, stats) => {
if(err) {
throw new gutil.PluginError("webpack", err);
}

gutil.log("[webpack]", stats.toString({
colors: colorsSupported,
chunks: false,
errorDetails: true
}));

cb();
});
});

gulp.task('serve', () => {
const config = require('./webpack.dev.config');
config.entry.app = [
// this modules required to make HRM working
// it responsible for all this webpack magic
'webpack-hot-middleware/client?reload=true',
// application entry point
].concat(paths.entry);

var compiler = webpack(config);

serve({
port: process.env.PORT || 3000,
open: false,
server: {baseDir: root},
middleware: [
historyApiFallback(),
webpackDevMiddleware(compiler, {
stats: {
colors: colorsSupported,
chunks: false,
modules: false
},
publicPath: config.output.publicPath
}),
webpackHotMiddleware(compiler)
]
});
});

gulp.task('watch', ['serve']);
const blankTemplates = path.join(__dirname, 'generator', 'component/**/*.**');

gulp.task('component', () => {
const cap = (val) => {
Expand All @@ -105,7 +25,7 @@ gulp.task('component', () => {
const parentPath = yargs.argv.parent || '';
const destPath = path.join(resolveToComponents(), parentPath, name);

return gulp.src(paths.blankTemplates)
return gulp.src(blankTemplates)
.pipe(template({
name: name,
upCaseName: cap(name)
Expand All @@ -115,12 +35,3 @@ gulp.task('component', () => {
}))
.pipe(gulp.dest(destPath));
});

gulp.task('clean', (cb) => {
del([paths.dest]).then(function (paths) {
gutil.log("[clean]", paths);
cb();
})
});

gulp.task('default', ['watch']);
68 changes: 0 additions & 68 deletions karma.conf.js

This file was deleted.

Loading