const componentsJs = () =>
gulp
.src('./**/src/js/App.js')
.pipe(webpackStream({
mode: 'development',
output: {
filename: 'component.min.js',
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
loader: 'babel-loader',
query: {
presets: [
["@babel/preset-env"]
],
},
},
],
},
}), webpack)
.pipe(gulp.dest((file) => file.base));
const named = require('vinyl-named-with-path');
// Принимает объект(file) из плагина rename и обрезает указанное(deep) количество папок с конца строки
const changeDirToParent = (file, deep = 1) => {
file.dirname = file.dirname
.split("/")
.slice(0, -1 * deep)
.join("/");
};
const js = () => {
return gulp
.src("**/src/js/App.js", { dot: true, ignore: EXCLUDED_PATH })
.pipe(plumber())
.pipe(named())
.pipe(webpackStream({
mode: "development",
output: {
filename: "[name]/script.min.js",
},
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules)/,
loader: "babel-loader",
query: {
presets: [["@babel/preset-env"]],
},
},
],
},
}))
.pipe(
rename((path) => {
// Мне нужно не в ту же директорию, а на две выше
changeDirToParent(path, 3);
})
)
.pipe(uglify())
.pipe(gulp.dest("./"));
};