Skip to content

Instantly share code, notes, and snippets.

@stefthoen
Created December 6, 2019 13:07
Show Gist options
  • Save stefthoen/fd94dbe96e75fba942c9c41eaf2fd6bd to your computer and use it in GitHub Desktop.
Save stefthoen/fd94dbe96e75fba942c9c41eaf2fd6bd to your computer and use it in GitHub Desktop.
import { series, parallel, src, dest, watch } from "gulp";
import babel from "gulp-babel";
import yargs from "yargs";
import gulpif from "gulp-if";
import webpack from "webpack-stream";
const production = yargs.argv.prod;
const basePath = "../";
const paths = {
js: `${basePath}src/js/**.js`,
images: `${basePath}build/static/img/*.{jpg,jpeg,png,svg,gif}`
};
export const javascript = () => {
return src(paths.js)
.pipe(babel())
.pipe(
webpack({
module: {
rules: [
{
test: /\.js$/,
use: {
loader: "babel-loader",
options: {
presets: []
}
}
}
]
},
mode: production ? "production" : "development",
devtool: !production ? "inline-source-map" : false,
output: {
filename: "bundle.js"
}
})
)
.pipe(dest(`${basePath}dist/js`, { sourcemaps: true }));
};
export const images = () => {
return src(paths.images).pipe(dest(`${basePath}dist/img`));
};
export const observe = () => {
watch(paths.js, javascript);
watch(paths.images, images);
};
export const dev = series(parallel(javascript, images), observe);
exports.default = parallel(javascript, images);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment