1

grunt-connect-proxy を gruntfile.js に gruntfile.js に追加しようとしていますが、それが書かれている方法が変更されているため、動作させることができないようです。 Grunt の仕組みに不慣れです。

これに関する多くの投稿を読みましたが、特に最新のものはなく、gruntfile は livereload ミドルウェアの実装方法で頻繁に変更されているようです。これにより、私の場合、grunt-connect-proxy のドキュメントが機能しなくなります。

トリッキーな部分は livereload の下にあります

これは、generator-angular gruntfile でどのように見えるかです。

// The actual grunt server settings
connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',
    livereload: 35729
  },
  proxies: [{
      context: '/api',
      host: 'localhost',
      port: 8080,
      https: false,
      xforward: false
    }],
  livereload: {
    options: {
      open: true,

      // --- how the code looks like before I do anything

      middleware: function (connect) {
        return [
          connect.static('.tmp'),
          connect().use('/bower_components', connect.static('./bower_components')),
          connect().use('/app/styles', connect.static('./app/styles')),
          connect.static(appConfig.app)
        ];
      }
    }
  },
  ...

ドキュメントを見ると、次のようになっています。

    livereload: {
        options: {
            middleware: function (connect, options) {
                if (!Array.isArray(options.base)) {
                    options.base = [options.base];
                }

                // Setup the proxy
                var middlewares = [require('grunt-connect-proxy/lib/utils').proxyRequest];

                // Serve static files.
                options.base.forEach(function(base) {
                    middlewares.push(connect.static(base));
                });

                // Make directory browse-able.
                var directory = options.directory || options.base[options.base.length - 1];
                middlewares.push(connect.directory(directory));

                return middlewares;
            }
        }
    }

ドキュメントをミドルウェア部分の新しい書き方に翻訳するのを手伝ってくれる人はいますか?

ありがとう!!

4

1 に答える 1