Skip to content

Commit

Permalink
Fix watch
Browse files Browse the repository at this point in the history
  • Loading branch information
IbeVanmeenen committed Jul 27, 2017
1 parent 3ae8dc0 commit 63ee6c1
Show file tree
Hide file tree
Showing 15 changed files with 235 additions and 209 deletions.
6 changes: 2 additions & 4 deletions generators/app/templates/_package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
{
"name": "<%= appName %>",
"version": "1.0.0",
"dependencies": {

},
"dependencies": {},
"devDependencies": {
"gulp": "github:gulpjs/gulp#4.0",
"gulp-changed": "~2.0",
Expand Down Expand Up @@ -44,6 +42,6 @@
],
"scripts": {
"dev": "gulp --require babel-register --gulpfile tasks",
"build": "gulp --require babel-register --gulpfile tasks build"
"build": "gulp --require babel-register --gulpfile tasks build --production"
}
}
6 changes: 3 additions & 3 deletions generators/app/templates/dev/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="<%= appName %>">

<link rel="stylesheet" href="<%= distFolderPath %>/css/style.min.css">
<link rel="stylesheet" href="./assets/css/style.min.css">

<link rel="apple-touch-icon-precomposed" sizes="57x57" href="/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon-precomposed" sizes="114x114" href="/apple-touch-icon-114x114.png">
Expand Down Expand Up @@ -41,7 +41,7 @@
<body>
<main role="main"></main>

<script src="<%= distFolderPath %>/js/vendors.min.js"></script>
<script src="<%= distFolderPath %>/js/app.min.js"></script>
<script src="./assets/js/vendors.min.js"></script>
<script src="./assets/js/app.min.js"></script>
</body>
</html>
54 changes: 31 additions & 23 deletions generators/app/templates/styleguide/tasks/styleguide.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,41 @@ const sourcePath = path.join(config.root.dev, config.styleguide.dev);
const distPath = path.join(config.root.dist, config.styleguide.dist);

const styleguideConfig = {
'layout': 'default',
'layouts': sourcePath + '/views/layouts/*',
'layoutIncludes': sourcePath + '/views/layouts/includes/*',
'views': [
sourcePath + '/views/**/*',
'!' + sourcePath + '/views/+(layouts)/**'
],
'materials': sourcePath + '/materials/**/*.html',
'data': sourcePath + '/data/**/*.{json,yml}',
'docs': sourcePath + '/docs/**/*.md',
'keys': {
'materials': 'materials',
'views': 'views',
'docs': 'docs'
},
'helpers': {},
'logErrors': false,
'dest': distPath
'layout': 'default',
'layouts': sourcePath + '/views/layouts/*',
'layoutIncludes': sourcePath + '/views/layouts/includes/*',
'views': [
sourcePath + '/views/**/*',
'!' + sourcePath + '/views/+(layouts)/**'
],
'materials': sourcePath + '/materials/**/*.html',
'data': sourcePath + '/data/**/*.{json,yml}',
'docs': sourcePath + '/docs/**/*.md',
'keys': {
'materials': 'materials',
'views': 'views',
'docs': 'docs'
},
'helpers': {},
'logErrors': false,
'dest': distPath
};


const styleguide = () => {
export const styleguide = () => {

return new Promise((resolve) => {
assemble(styleguideConfig);
resolve();
});
return new Promise((resolve) => {
assemble(styleguideConfig);
resolve();
});
};


export const watch = () => {
gulp.watch(styleguideConfig.layouts, gulp.series(styleguide));
gulp.watch(styleguideConfig.layoutIncludes, gulp.series(styleguide));
gulp.watch(styleguideConfig.views, gulp.series(styleguide));
gulp.watch(styleguideConfig.materials, gulp.series(styleguide));
};


Expand Down
8 changes: 4 additions & 4 deletions generators/app/templates/tasks/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import del from 'del';
import config from './config/general';


const clean = () => {
export const clean = () => {

return del(config.root.dist, {
force: true
});
return del(config.root.dist, {
force: true
});
};


Expand Down
58 changes: 29 additions & 29 deletions generators/app/templates/tasks/config/general.json
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
{
"root": {
"dev": "<%= devFolderPath %>",
"dist": "<%= distFolderPath %>"
},
"javascript": {
"dev": "js",
"dist": "assets/js",
"extensions": [".json", ".js"]
},
"styles": {
"dev": "scss/**/*",
"dist": "assets/css",
"extensions": ".scss"
},
"images": {
"dev": "img/**/*",
"dist": "assets/img",
"extensions": ".(jpg|png|svg|gif)"
},
"html": {
"dev": "html/**/*",
"dist": "./",
"extensions": ".html"
}<% if (hasStyleguide) { %>,
"styleguide": {
"dev": "styleguide",
"dist": "assets/styleguide",
"extensions": ".(html,json,md,yml)"
}<% } %>
"root": {
"dev": "<%= devFolderPath %>",
"dist": "<%= distFolderPath %>"
},
"javascript": {
"dev": "js",
"dist": "assets/js",
"extensions": [".json", ".js"]
},
"styles": {
"dev": "scss/**/*",
"dist": "assets/css",
"extensions": ".scss"
},
"images": {
"dev": "img/**/*",
"dist": "assets/img",
"extensions": ".(jpg|png|svg|gif)"
},
"html": {
"dev": "html/**/*",
"dist": "./",
"extensions": ".html"
}<% if (hasStyleguide) { %>,
"styleguide": {
"dev": "styleguide",
"dist": "assets/styleguide",
"extensions": ".(html,json,md,yml)"
}<% } %>
}
80 changes: 40 additions & 40 deletions generators/app/templates/tasks/config/webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,55 +20,55 @@ const plugins = [];
plugins.push(new webpack.NoEmitOnErrorsPlugin());

plugins.push(new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
filename: 'vendors.min.js'
name: 'vendor',
filename: 'vendors.min.js'
}));


if (isProduction()) {
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.NoEmitOnErrorsPlugin()
);
plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new webpack.NoEmitOnErrorsPlugin()
);
} else {
plugins.push(new webpack.HotModuleReplacementPlugin());
plugins.push(new webpack.HotModuleReplacementPlugin());
}


const webpackConfig = {
cache: true,
context: sourcePath,
entry: {
app: './app.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: path.resolve(__dirname, 'node_modules/'),
loader: 'babel-loader',
options: {
presets: [['es2015', {
modules: false
}]]
}
}
]
},
output: {
path: distPath,
filename: 'app.min.js',
publicPath: config.javascript.dist
},
resolve: {
modules: [sourcePath, 'node_modules'],
extensions: config.javascript.extensions
},
plugins: plugins
cache: true,
context: sourcePath,
entry: {
app: './app.js',
},
module: {
rules: [
{
test: /\.js$/,
exclude: path.resolve(__dirname, 'node_modules/'),
loader: 'babel-loader',
options: {
presets: [['es2015', {
modules: false
}]]
}
}
]
},
output: {
path: distPath,
filename: 'app.min.js',
publicPath: config.javascript.dist
},
resolve: {
modules: [sourcePath, 'node_modules'],
extensions: config.javascript.extensions
},
plugins: plugins
};


Expand Down
2 changes: 1 addition & 1 deletion generators/app/templates/tasks/helpers/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import gutil from 'gulp-util';


const isProduction = () => {
return gutil.env.production;
return gutil.env.production;
};


Expand Down
10 changes: 5 additions & 5 deletions generators/app/templates/tasks/helpers/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import gutil from 'gulp-util';


const errorLogger = (taskName, message) => {
throw new gutil.PluginError({
plugin: taskName,
message: gutil.colors.red(message)
});
throw new gutil.PluginError({
plugin: taskName,
message: gutil.colors.red(message)
});
};

const infoLogger = (taskName, message) => {
gutil.log(taskName, gutil.colors.magenta(message));
gutil.log(taskName, gutil.colors.magenta(message));
};


Expand Down
13 changes: 9 additions & 4 deletions generators/app/templates/tasks/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,16 @@ const sourceFiles = path.join(config.root.dev, config.html.dev) + config.html.ex
const distPath = path.join(config.root.dist, config.html.dist);


const html = () => {
return gulp.src(sourceFiles)
export const html = () => {
return gulp.src(sourceFiles)

// Set desitination
.pipe(gulp.dest(distPath));
// Set desitination
.pipe(gulp.dest(distPath));
};


export const watch = () => {
gulp.watch(sourceFiles, gulp.series(html));
};


Expand Down
59 changes: 32 additions & 27 deletions generators/app/templates/tasks/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,38 @@ const sourceFiles = path.join(config.root.dev, config.images.dev) + config.image
const distPath = path.join(config.root.dist, config.images.dist);


const images = () => {
return gulp.src(sourceFiles)
// Stop Plumber
.pipe(plumber())

// Only optimize changed images
.pipe(changed(distPath))

// Imagemin
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
svgoPlugins: [{
removeViewBox: false
}]
}))

// Stop Plumber
.pipe(plumber.stop())

// Set desitination
.pipe(gulp.dest(distPath))

// Show total size of images
.pipe(size({
title: 'images'
}));
export const images = () => {
return gulp.src(sourceFiles)
// Stop Plumber
.pipe(plumber())

// Only optimize changed images
.pipe(changed(distPath))

// Imagemin
.pipe(imagemin({
optimizationLevel: 3,
progressive: true,
svgoPlugins: [{
removeViewBox: false
}]
}))

// Stop Plumber
.pipe(plumber.stop())

// Set desitination
.pipe(gulp.dest(distPath))

// Show total size of images
.pipe(size({
title: 'images'
}));
};


export const watch = () => {
gulp.watch(sourceFiles, gulp.series(images));
};


Expand Down
Loading

0 comments on commit 63ee6c1

Please sign in to comment.