【问题标题】:Gulp, browserify and remapifyGulp、browserify 和 remapify
【发布时间】:2014-05-14 12:25:31
【问题描述】:

我正在尝试找到一种使用 browserify 和 gulp 映射目录的好方法,所以我没有很多路径链接:

var uriparser = require('../../../app/assets/javascripts/app/module/mymodule.coffee')

所以我一直在尝试将 remapify 与 gulp 一起使用,所以我有这样的食谱:

var gulp = require('gulp');
var browserify = require('browserify');
var remapify = require('remapify');
var source = require('vinyl-source-stream');

gulp.task("test", function () {
  var b = browserify({entries:['./spec/javascripts/modules/tests.coffee'],
    extensions: ['.coffee']
  });

  b.plugin(remapify, [
    {
      src: './app/assets/javascripts/app/**/*.coffee'
      , expose: 'app'
      , cwd:__dirname
    }

  ])



  libs.forEach(function (lib) {
    b.external(lib);
  });



  return b.bundle()
    .pipe(source("app.js"))
    .pipe(gulp.dest('./spec/javascripts/specs/helpers'));
});

不确定我错过了什么,但它根本没有正确映射路径,也许这不是最好的工具,但尝试了很多选项都没有成功,所以任何帮助都会很棒!

【问题讨论】:

    标签: coffeescript gulp browserify


    【解决方案1】:

    您至少有一个问题,原因是:https://github.com/joeybaker/remapify/pull/4

    Remapify 目前不支持“coffee”之类的扩展。您可以先使用https://github.com/gruntjs/grunt-contrib-coffee 将您的 CoffeeScript 编译成 JavaScript,然后再重新映射。

    【讨论】:

      【解决方案2】:

      Remapify 现在尊重 browserify 中配置的扩展列表。默认情况下这是jsjson,但您可以通过extensions browserify 选项更改它。不确定 gulp 中的格式是什么,但这是我在 grunt 中所做的:

        grunt.initConfig
          browserify:
            app:
              dest: 'public/scripts/main.js'
              src: ['client/app/**/*.coffee']
              options:
                preBundleCB: (b) ->
                  b.plugin remapify, [
                    cwd: './client/app'
                    src: '**/*.coffee'
                    expose: 'app'
                  ]
      
                transform: ['coffeeify']
                browserifyOptions:
                  debug: true
                  extensions: ['.coffee', '.js']
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-04-12
        相关资源
        最近更新 更多