Created
December 6, 2019 13:07
-
-
Save stefthoen/fd94dbe96e75fba942c9c41eaf2fd6bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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