jsoverson / preprocess

Preprocess HTML, JavaScript, and other files with directives based off custom or ENV configuration
Other
366 stars 80 forks source link

How to write CoffeeScript directive #108

Closed Shyam-Chen closed 8 years ago

Shyam-Chen commented 8 years ago

not working

# error
require './modules'
# @if ENV='prod'
require './templates'
# @endif

angular
  .module 'app', [
    'ngComponentRouter'
    'ngMaterial'
    'firebase'
    'app.core'
    'app.shared'
    # @if ENV='prod'
    'app.template'
    # @endif
  ]
# error message
Cannot find module './templates'
# ok (bad practice)
require './modules'
`/* @if ENV='prod' **`
require './templates'
`/* @endif */`

angular
  .module 'app', [
    'ngComponentRouter'
    'ngMaterial'
    'firebase'
    'app.core'
    'app.shared'
    `/* @if ENV='prod' **`
    'app.template'
    `/* @endif */`
  ]
# gulpfile.coffee
[...]
preprocessify = require 'preprocessify'
[...]
    firstBundle = ->
      bundler
        .transform preprocessify (ENV: 'dev'), includeExtensions: '.coffee'
        .bundle()
        .on 'error', handleCompileErrors
        .pipe bundleShared()
[...]
Shyam-Chen commented 8 years ago
# ok
require './modules'

di = [
  'ngComponentRouter'
  'ngMaterial'
  'firebase'
  'app.core'
  'app.shared'
]

### @if ENV='prod' ###
require './templates'
di.push 'app.template'
### @endif ###

angular.module 'app', di
Shyam-Chen commented 8 years ago

Test failed

Shyam-Chen commented 8 years ago
# karma.conf.coffee
# ok
preprocessify = require 'preprocessify'
[...]
    transform: [
      'coffeeify', [
        preprocessify (ENV: 'dev'), includeExtensions: '.coffee'
      ]
    ]
[...]