-->

Replace broccoli-sass with broccoli-compass in bro

2020-03-07 05:18发布

问题:

I'm attempting to replace broccoli-sass with broccoli-compass, in the Broccoli Ember Sample.

My app structure looks like:

app
public
styles
  app.scss

Brocfile:

...
var compileSass = require('broccoli-compass')
...
var appNamespace = 'my-app-name';

function preprocess (tree) {
  tree = filterTemplates(tree, {
    extensions: ['hbs', 'handlebars'],
    compileFunction: 'Ember.Handlebars.compile'
  })

  return tree
}

var app = 'app'
app = pickFiles(app, {
  srcDir: '/',
  destDir: appNamespace // move under app namespace
})
app = preprocess(app)

var styles = 'styles'
styles = pickFiles(styles, {
  srcDir: '/',
  destDir: appNamespace
})
styles = preprocess(styles)

var tests = 'tests'
tests = pickFiles(tests, {
  srcDir: '/',
  destDir: appNamespace + '/tests'
})
tests = preprocess(tests)

var vendor = 'vendor'

var sourceTrees = [app, styles, vendor]
if (env !== 'production') {
  sourceTrees.push(tests)
}
sourceTrees = sourceTrees.concat(findBowerTrees())

var appAndDependencies = new mergeTrees(sourceTrees, { overwrite: true })

var appJs = compileES6(appAndDependencies, {
  loaderFile: 'loader.js',
  ignoredModules: [
    'ember/resolver'
  ],
  inputFiles: [
    appNamespace + '/**/*.js'
  ],
  legacyFilesToAppend: [
    'jquery.js',
    'handlebars.js',
    'ember.js',
    'ember-resolver.js'
  ],
  wrapInEval: false,
  outputFile: '/assets/app.js'
})

var appCss = compileSass(appAndDependencies, 'styles/app.scss')

var publicFiles = 'public'

module.exports = mergeTrees([appJs, appCss, publicFiles])

However, I'm getting the following error when calling broccoli serve:

[broccoli-compass] Error: No such file or directory - /Users/my.name/Documents/Code/broccoli-ember/tmp/tree_merger-tmp_dest_dir-4rW9S0CD.tmp/styles/app.scss

Any idea what I'm missing here?

回答1:

I changed the brocfile styles preprocess to:

var styles = 'styles'
styles = pickFiles(styles, {
  srcDir: '/',
  destDir: appNamespace + '/styles'
})
styles = preprocess(styles)

and the compileSass call to:

var appCss = compileSass(appAndDependencies, appNamespace + '/styles/app.scss', {
    outputStyle: 'expanded',
    sassDir: appNamespace + '/styles',
    imagesDir: 'public/images/',
    cssDir: '/assets'
})

Similar to the answer here - Compiling Compass in an Ember-CLI project