How to import or include javascript file in gulp file

How can I import or add my own javascript file to gulpfile?

Gulp is installed through npm, so I can enable other npm modules, for example:

var sass = require('gulp-sass');

So, I would like to do something like:

var karmaConfig = require('karma-config.js');

The directory structure looks like this:

node_modules/
gulpfile.js
package.json
karma-config.js

so the gulpfile is at the same level as the file I want to import.

+4
source share
2 answers

(I can not comment because of rep)

If your file is called karma-config, I assume it is a configuration file, so why did you make it .js instead of .json? I don't know anything about importing .js into gulpfile, but importing .json works fine.

- karmaConfig = require('./karma-config.js');? ( ) , ./ . , ?

+3

:

var karmaConfig = require('./karma-config');

karmaConfig.

hendrikswan , .js . .

./ , , node_modules. :

node_modules/
gulpfile.js
package.json
config/karma.js

:

var karmaConfig = require('./config/karma');
+3

Source: https://habr.com/ru/post/1542276/


All Articles