我的WebStorm 2016 IDE中有以下gulpfile.js
。我的SCSS样式表目前位于src/scss/style.scss
,我在那里完成了@ import' s。
经过大量研究并花费数小时试图解决这个问题后,我无法在我的主scss文件中执行@import "bourbon";
。我猜测gulp文件中的某些内容不正确,其次我的IDE在我执行的任何npm包导入时显示红线(意味着它无法看到node_modules的正确路径)。
是否有人能够弄清楚如何配置?感谢任何帮助,谢谢。
gulfile.js
var gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
header = require('gulp-header'),
rename = require('gulp-rename'),
cssnano = require('gulp-cssnano'),
package = require('./package.json');
var paths = {
scss: './src/scss/*.scss'
};
var sass_config = { // THE INCLUDES FOR BOTH PROD AND DEV
includePaths: [
require('node-neat').includePaths
],
style: 'compressed',
quiet: true,
sourcemap: true
};
var banner = [
'/*!\n' +
' * <%= package.name %>\n' +
' * <%= package.title %>\n' +
' * <%= package.url %>\n' +
' * @author <%= package.author %>\n' +
' * @version <%= package.version %>\n' +
' * Copyright ' + new Date().getFullYear() + '. <%= package.license %> licensed.\n' +
' */',
'\n'
].join('');
gulp.task('css', function () {
return gulp.src(paths.scss)
.pipe(sass(sass_config).on('error', sass.logError))
.pipe(autoprefixer('last 4 version'))
.pipe(gulp.dest('app/assets/css'))
.pipe(cssnano())
.pipe(rename({ suffix: '.min' }))
.pipe(header(banner, { package : package }))
.pipe(gulp.dest('app/assets/css'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('js',function(){
gulp.src('src/js/scripts.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(header(banner, { package : package }))
.pipe(gulp.dest('app/assets/js'))
.pipe(uglify())
.pipe(header(banner, { package : package }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('app/assets/js'))
.pipe(browserSync.reload({stream:true, once: true}));
});
gulp.task('browser-sync', function() {
browserSync.init(null, {
server: {
baseDir: "app"
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('default', ['css', 'js', 'browser-sync'], function () {
gulp.watch("src/scss/*/*.scss", ['css']);
gulp.watch("src/js/*.js", ['js']);
gulp.watch("app/*.html", ['bs-reload']);
});
答案 0 :(得分:0)
下面的代码调整让我的Bourbon和Neat开始通过我的SCSS文件中的导入工作。但是,我仍然遇到WebStorm的问题,在@import“bourbon”下给我一个红色下划线,在IDE中出现错误“无法解析文件波本威士忌”。但是,它正在工作,所以我在想它不能解决正确的路径。如果有人知道解决方案,请发表评论。
var gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
autoprefixer = require('gulp-autoprefixer'),
uglify = require('gulp-uglify'),
jshint = require('gulp-jshint'),
header = require('gulp-header'),
rename = require('gulp-rename'),
cssnano = require('gulp-cssnano'),
package = require('./package.json');
var paths = {
scss: 'src/scss/*.scss'
};
var sass_config = { // THE INCLUDES FOR BOTH PROD AND DEV
includePaths: require('node-neat').includePaths,
style: 'compressed',
quiet: true,
sourcemap: true
};
var banner = [
'/*!\n' +
' * <%= package.name %>\n' +
' * <%= package.title %>\n' +
' * <%= package.url %>\n' +
' * @author <%= package.author %>\n' +
' * @version <%= package.version %>\n' +
' * Copyright ' + new Date().getFullYear() + '. <%= package.license %> licensed.\n' +
' */',
'\n'
].join('');
gulp.task('css', function () {
return gulp.src(paths.scss)
.pipe(sass(sass_config).on('error', sass.logError))
.pipe(autoprefixer('last 4 version'))
.pipe(gulp.dest('app/assets/css'))
.pipe(cssnano())
.pipe(rename({ suffix: '.min' }))
.pipe(header(banner, { package : package }))
.pipe(gulp.dest('app/assets/css'))
.pipe(browserSync.reload({stream:true}));
});
gulp.task('js',function(){
gulp.src('src/js/scripts.js')
.pipe(jshint('.jshintrc'))
.pipe(jshint.reporter('default'))
.pipe(header(banner, { package : package }))
.pipe(gulp.dest('app/assets/js'))
.pipe(uglify())
.pipe(header(banner, { package : package }))
.pipe(rename({ suffix: '.min' }))
.pipe(gulp.dest('app/assets/js'))
.pipe(browserSync.reload({stream:true, once: true}));
});
gulp.task('browser-sync', function() {
browserSync.init(null, {
server: {
baseDir: "app"
}
});
});
gulp.task('bs-reload', function () {
browserSync.reload();
});
gulp.task('default', ['css', 'js', 'browser-sync'], function () {
gulp.watch("src/scss/**/*.scss", ['css']);
gulp.watch("src/js/*.js", ['js']);
gulp.watch("app/*.html", ['bs-reload']);
});
答案 1 :(得分:0)
require('node-neat').includePaths
本身就是一个数组,includePaths
变量中的 sass_config
选项应该是一个数组本身,而不是一个数组数组。因此,正如您已经提到的,可能的解决方案是将 require('node-neat').includePaths
传递给 includePaths
选项,因为它没有方括号,如下所示:
var sass_config = {
includePaths: require('node-neat').includePaths,
...
};
为了传递这种类型的多个数组,您也可以尝试像这样连接它们:
var sass_config = {
includePaths: [].concat(
require('node-neat').includePaths,
require('bourbon').includePaths
),
...
};
至于 WebStorm/PhpStorm 中导入库时的错误,请检查 answer by @Shawn Lovelidge。
基本上,您必须遵循以下步骤:
File
菜单> Settings
(或按Ctrl+Alt+S)Directories
node_modules
目录并选中 Resource Root
选项Resource Root
按钮)。