Answer the question
In order to leave comments, you need to log in
Gulp + webpack-stream - How to save generated file in the same directory?
Greetings!
Please help me figure out what needs to be done so that js is created in the same directory as the source?
The file is now generated in the root of the project, but it is necessary in the same folder as the source file (In general, it is needed two levels higher, but this is not important now).
It seems that webpackStream overwrites base and you need to pass the path to its config in output / path. That's just how?
Now the thread looks like this:
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));
Answer the question
In order to leave comments, you need to log in
Got it! This will require the vinyl-named-with-path plugin
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: ,
},
},
],
},
}))
.pipe(
rename((path) => {
// Мне нужно не в ту же директорию, а на две выше
changeDirToParent(path, 3);
})
)
.pipe(uglify())
.pipe(gulp.dest("./"));
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question