A
A
Alexander Rogachev2017-03-24 13:07:21
JavaScript
Alexander Rogachev, 2017-03-24 13:07:21

How to import one stylus file into several others using gulp?

There is a big bunch of stylus files, they should be compiled into css, but not assembled into one, because of this there is a small problem, I would not want to write import variable.styl in each file. And I would like this import to make a gallp during assembly, i.e. I imported variable.styl into each file.
gulpfile.js code

gulp.task('stylus', function () {
    gulp.src(['source/styl_variable/*.styl', 'source/Layout-Desktop/stylus/*.styl'])
      .pipe(stylus({
        import: 'variable.styl'
      }))
      .pipe(gulp.dest('build')
});

When processing each file, the following error appears: Is there any solution to this problem without resorting to pushing imports in each styl file?
failed to locate @import file variable.styl

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Rogachev, 2017-03-24
@volkano

Since the option with concat did not work for me. I went the other way. With gulp-insert, I added the contents of one file to another. The code turned out like this -

...//подключаем галп и все такое
var insert = require('gulp-insert');
var fs = require("fs")
gulp.task('stylus', function () {
  var variableContent = fs.readFileSync("source/styl_variable/variable.styl", "utf8");
  gulp.src('source/Layout-Desktop/stylus/*.styl')
  .pipe(insert.transform(function(contents, file) {
    return variableContent + '\n' + contents;       
  }))
  .pipe(gulp.dest('build'))

The '\n' + was added to allow for indentation between files.
If anyone has any ideas on how to solve this problem better, please advise. Since I tried a bunch of plugins and only this way gave the result.

E
Egor Zhivagin, 2017-03-24
@Krasnodar_etc

Is there any solution to this problem without resorting to pushing imports in each styl file?

Collect into one))
Maybe some gulp-concat will do?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question