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

Get new dev/prod build process from air-light #5

Merged
merged 2 commits into from
Feb 19, 2021
Merged
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
23 changes: 11 additions & 12 deletions gulp/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ module.exports = {
},
styles: {
gutenberg: themeDir + '/sass/base/gutenberg.scss',
main: themeDir + '/sass/base/global.scss',
src: themeDir + '/sass/**/*.{sass,scss}',
dest: themeDir + '/css',
exclude: ['!' + themeDir + '/sass/navigation/_burger.scss', '!' + themeDir + '/sass/base/_normalize.scss'],
src: themeDir + '/sass/*.scss',
watch: themeDir + '/sass/**/*.{sass,scss}',
development: themeDir + '/css/dev/',
production: themeDir + '/css/prod/',
stylelint: {
opts: {
fix: false,
Expand All @@ -73,29 +73,28 @@ module.exports = {
opts: {
development: {
bundleExec: true,
style: 'expanded',
outputStyle: 'expanded',
debugInfo: true,
lineNumbers: true,
errLogToConsole: true,
includePaths: [themeDir + '/node_modules/']
},
production: {
bundleExec: true,
style: 'compressed',
outputStyle: 'compressed',
debugInfo: true,
lineNumbers: true,
errLogToConsole: true,
includePaths: [themeDir + '/node_modules/']
}
}
},
js: {
main: themeDir + '/js/src/*.js',
src: themeDir + '/js/src/**/*.js',
dest: themeDir + '/js/dist/'
src: themeDir + '/js/src/*.js',
watch: themeDir + '/js/src/**/*',
production: themeDir + '/js/prod/',
development: themeDir + '/js/dev/',
},
php: {
src: themeDir + '/**/*.php'
src: '**/*.php'
},
phpcs: {
src: [themeDir + '/**/*.php', '!' + themeDir + '/node_modules/**/*'],
Expand Down
32 changes: 22 additions & 10 deletions gulp/tasks/js.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,38 @@ process.env.NODE_PENDING_DEPRECATION = 0;
// Dependencies
const {
dest,
src,
src
} = require('gulp');
const webpack = require('webpack-stream');
const named = require('vinyl-named');
const eslint = require('gulp-eslint');
const config = require('../config');
const {
handleError,
handleError
} = require('../helpers/handle-errors.js');
const webpackConfig = require('../webpack.config.js');
const webpackConfigProduction = require('../webpack.config.prod.js');
const webpackConfigDevelopment = require('../webpack.config.dev.js');
const named = require('vinyl-named');
const eslint = require('gulp-eslint');

// Task
function js() {
return src(config.js.src)
.pipe(eslint())
.pipe(eslint.format())
const lintedJs = src(config.js.src)
.pipe(eslint())
.pipe(eslint.format());

const production = lintedJs
.pipe(named())
.pipe(webpack(webpackConfig))
.pipe(webpack(webpackConfigProduction))
.on('error', handleError())
.pipe(dest(config.js.dest));
.pipe(dest(config.js.production));

const development = lintedJs
.pipe(named())
.pipe(webpack(webpackConfigDevelopment))
.on('error', handleError())
.pipe(dest(config.js.development));


return { production, development };
}

exports.js = js;
2 changes: 1 addition & 1 deletion gulp/tasks/scsslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const config = require('../config.js');
// Task
function scsslint() {

return src(config.styles.src, config.styles.exclude)
return src([config.styles.src])

// Print linter report
.pipe(stylelint(config.styles.stylelint.opts));
Expand Down
35 changes: 3 additions & 32 deletions gulp/tasks/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ const notify = require('gulp-notify');
const mqpacker = require('mqpacker');

function styles(done) {
return src(config.styles.main)
return src(config.styles.src)
.pipe(sass(config.styles.opts.development))

// Run PostCSS plugins
.pipe(postcss([autoprefixer(), mqpacker()]))

// Save expanded version for development
.pipe(dest(config.styles.dest))
.pipe(dest(config.styles.development))

// Production settings
.pipe(sass(config.styles.opts.production))
Expand All @@ -38,35 +38,7 @@ function styles(done) {
}), )

// Save minified version for production
.pipe(rename(config.rename.min))
.pipe(dest(config.styles.dest))

// Inject changes to browser
.pipe(bs.stream());

done();
}

function gutenbergstyles(done) {

return src(config.styles.gutenberg)
.pipe(sass(config.styles.opts.development))

// Production settings
.pipe(sass(config.styles.opts.production))
.pipe(postcss([autoprefixer()]))

.pipe(cleancss(config.cleancss.opts,
function (details) {
console.log('[clean-css] Original: ' + details.stats.originalSize / 1000 + ' kB');
console.log('[clean-css] Minified: ' + details.stats.minifiedSize / 1000 + ' kB');
console.log('[clean-css] Compression time: ' + details.stats.timeSpent + ' ms', );
console.log('[clean-css] Compression rate: ' + details.stats.efficiency * 100 + ' %', );
}), )

// Save minified version for production
.pipe(rename(config.rename.min))
.pipe(dest(config.styles.dest))
.pipe(dest(config.styles.production))

// Inject changes to browser
.pipe(bs.stream());
Expand All @@ -75,4 +47,3 @@ function gutenbergstyles(done) {
}

exports.styles = styles;
exports.gutenbergstyles = gutenbergstyles;
6 changes: 3 additions & 3 deletions gulp/tasks/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const {
// Task
function watchfiles() {
bs.init(config.browsersync.src, config.browsersync.opts);
watch(config.styles.src, series('styles', 'gutenbergstyles', 'scsslint')).on('error', handleError('styles'));
watch(config.styles.watch, series('styles', 'scsslint')).on('error', handleError('styles'));
watch(config.php.src, series('phpcs')).on('change', bs.reload);
watch(config.js.src).on('change', series('js'));
watch(config.js.src).on('change', bs.reload);
watch(config.js.watch).on('change', series('js'));
watch(config.js.watch).on('change', bs.reload);
};

exports.watch = watchfiles;
27 changes: 27 additions & 0 deletions gulp/webpack.config.dev.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

module.exports = {
externals: {
jquery: 'jQuery' // Available and loaded through WordPress.
},
mode: 'development',
module: {
rules: [{
test: /.js$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader',
query: {
presets: [
['airbnb', {
targets: {
chrome: 50,
ie: 11,
firefox: 45
}
}]
]
}
}]
}]
}
};
1 change: 0 additions & 1 deletion gulp/webpack.config.js → gulp/webpack.config.prod.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');

module.exports = {
Expand Down
1 change: 0 additions & 1 deletion gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@ exports.js = require('./gulp/tasks/js.js').js;
exports.phpcs = require('./gulp/tasks/phpcs.js').phpcs;
exports.scsslint = require('./gulp/tasks/scsslint.js').scsslint;
exports.styles = require('./gulp/tasks/styles.js').styles;
exports.gutenbergstyles = require('./gulp/tasks/styles.js').gutenbergstyles;
exports.watch = require('./gulp/tasks/watch.js').watch;
exports.default = require('./gulp/tasks/watch.js').watch;