【发布时间】:2021-04-16 22:35:28
【问题描述】:
我正在开发两个共享相同依赖项的 SCSS 项目(Bootstrap、Fontawesome、node.js)。我想在根目录维护相同的依赖项并将 gulpfile.js 移动到项目子目录。
如何获取项目一和二子目录中的 gulpfile.js 文件以使用父/根目录中的 node_modules,同时保持样式和监视功能相对于它们的目录?
示例目录结构
|-- bootstrap
|-- node_modules
|-- package.json
|-- project_one
| |-- index.html
| |-- gulpfile.js
| |-- sass
|-- project_two
| |-- index.html
| |-- gulpfile.js
| |-- sass
Gulfile.js 代码
const gulp = require('gulp');
const sass = require('gulp-sass');
const browsersync = require('browser-sync').create();
// Compile scss int css
function style() {
return gulp.src('./sass/**/*.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./'))
.pipe(browsersync.stream());
}
// Watch function
function watch() {
browsersync.init({
server: {
baseDir: './'
}
});
gulp.watch('./sass/**/*.css', style);
gulp.watch('./**/*.html').on('change', browserSync.reload);
}
exports.style = style;
exports.watch = watch;
【问题讨论】:
-
我相信,只要您的导入正确,这应该不是问题。您还可以查看 React Workspaces(相当新),看看它是否可以解决您正在寻找的一些问题(会输入更多,但我在打电话)。
标签: node.js sass gulp gulp-sass