是否可以将我的变量放在gulpfile.js
之外?例如,这个块放入paths.js
:
path = {
css: 'web/default/css/',
scss: 'web/default/scss/',
js: 'web/default/js/',
images: 'web/default/images/',
imgDev: 'web/default/imgDev/',
imgRetina: 'web/default/imgDev/imgRetina/',
tplSprite: 'web/default/tools/',
tpl: 'themes/default/templates/',
versionBrowsers: 'last 2 versions',
srv: 'http://www.sbd.local/',
concatJsScripts: [
'web/default/js/assets/jquery.raty.js',
'web/default/js/assets/jquery.bxslider.min.js',
'web/default/js/assets/main.js'
]
};
并在我的gulpfile.js
中,致电path.srv
或path.js
由于
答案 0 :(得分:0)
您始终可以require
外部文件并访问所有导出的对象属性
// paths.js
'use strict';
module.exports = {
css: 'web/default/css/',
scss: 'web/default/scss/',
js: 'web/default/js/',
images: 'web/default/images/',
imgDev: 'web/default/imgDev/',
imgRetina: 'web/default/imgDev/imgRetina/',
tplSprite: 'web/default/tools/',
tpl: 'themes/default/templates/',
versionBrowsers: 'last 2 versions',
srv: 'http://www.sbd.local/',
concatJsScripts: [
'web/default/js/assets/jquery.raty.js',
'web/default/js/assets/jquery.bxslider.min.js',
'web/default/js/assets/main.js'
]
};
// gulpfile.js
'use strict';
var path = require('./paths.js');
// path to css
var css = path.css;
或者,您也可以定义路径JSON格式,使其看起来更像配置文件。
// paths.json
{
"css": "web/default/css/",
"scss": "web/default/scss/",
"js": "web/default/js/",
"images": "web/default/images/",
"imgDev": "web/default/imgDev/",
"imgRetina": "web/default/imgDev/imgRetina/",
"tplSprite": "web/default/tools/",
"tpl": "themes/default/templates/",
"versionBrowsers": "last 2 versions",
"srv": "http://www.sbd.local/",
"concatJsScripts": [
"web/default/js/assets/jquery.raty.js",
"web/default/js/assets/jquery.bxslider.min.js",
"web/default/js/assets/main.js"
]
};