angular – Karma.config:sass tilde importer

我通过angular-cli设置了一个角度为6的项目.

我安装了karma-scss-preprocessor作为dev依赖,在karma测试中加载sass文件.
关注karma.config:

...
config.set({
basePath: '',
browserNoActivityTimeout: 60000,
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
  require('karma-jasmine'),
  require('karma-chrome-launcher'),
  require('karma-phantomjs-launcher'),
  require('karma-jasmine-html-reporter'),
  require('karma-coverage-istanbul-reporter'),
  require('@angular-devkit/build-angular/plugins/karma'),
  require('karma-scss-preprocessor')
],
preprocessors: {
  'styles.scss': ['scss'],
},
files: [
  { pattern: 'styles.scss', watched: true,  included: true, served: true }
],
...

现在我收到错误:

File to import not found or unreadable: ~@onepackage/onelib/scss/all.

由于在styles.scss中导入onepackage / lib时的波浪号.

我试图在karma.json的插件部分添加require(‘node-sass-tilde-importer’),但它没有解决.

有什么建议吗?

最佳答案 你必须在karma-scss-preprocessor选项中调用require(‘node-sass-tilde-importer’)

...
plugins: [
  require('karma-jasmine'),
  require('karma-chrome-launcher'),
  require('karma-phantomjs-launcher'),
  require('karma-jasmine-html-reporter'),
  require('karma-coverage-istanbul-reporter'),
  require('@angular-devkit/build-angular/plugins/karma'),
  require('karma-scss-preprocessor')
],
scssPreprocessor: {
  options: {
    importer: require('node-sass-tilde-importer')
  }
},
...
点赞