yeoman / generator-angular HTML5Mode问题

时间:2014-12-26 05:18:28

标签: angularjs gruntjs yeoman-generator-angular yo connect-modrewrite

我正在运行你的--v 1.1.2和角度 - 发电机--v 0.10.0来创建一个新的应用程序,

启用HTML5Mode是a little bit tricky,因为当我在浏览器中点击URL时,我需要使用服务器重写来避免404错误。

所以我按照thread中的说明进行操作,显然它并没有使用最新版本的角度生成器。它在开发环境中工作得很好,但在生产dist目录上没有,dist中的资产文件没有正确加载,我得到404.

grunt serve #works great
grunt build #I get 404 on asset files and the baseurl is not correct.

关于如何使其发挥作用的任何想法?

这是我使用的grunt连接

    // 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,
    // Modrewrite rule, connect.static(path) for each path in target's base
    middleware: function (connect, options) {
      var optBase = (typeof options.base === 'string') ? [options.base] : options.base,
          middleware = [require('connect-modrewrite')(['!(\\..+)$ / [L]'])]
            .concat(optBase.map(function (path) { 
              if (path.indexOf('rewrite|') === -1) {
                return connect.static(path);
              } else {
                path = path.replace(/\\/g, '/').split('|');
                return  connect().use(path[1], connect.static(path[2]))
              }
            }));

      return middleware;
    }
  },
  livereload: {
    options: {
      open: true,
      base: [
        '.tmp',
        'rewrite|/bower_components|./bower_components',
        'rewrite|/app/styles|./app/styles', // for sourcemaps
        '<%= yeoman.app %>'
      ]
    }
  },
  test: {
    options: {
      port: 9001,
      base: [
        '.tmp',
        'test',
        'rewrite|/bower_components|./bower_components',
        'rewrite|/app/styles|./app/styles',
        '<%= yeoman.app %>'
      ]
    }
  },
  dist: {
    options: {
      base: '<%= yeoman.dist %>'
    }
  }
},

0 个答案:

没有答案