1

是否可以在 angular yeoman 生成器中重命名 index.html 文件?换句话说,我想使用不同的名称而不是 index.html

  • 更新

更具体

我希望 yeoman 也知道更改,以便当我生成新指令、服务时,控制器 yeoman 会将其写入“构建”块。IE

        <!-- build:js({.tmp,app}) scripts/scripts.js -->
    <script src="scripts/app.js"></script>
    <script src="scripts/controllers/main.js"></script>
    <!-- endbuild -->

我担心如果我重命名 index.html 文件,yeoman 将不知道名称更改,因此我的新 html 文件将需要使用我的指令、控制器、服务的新脚本标记手动更新。

4

1 回答 1

2

是的,这是可能的。但是你必须改变你的 Gruntfile.js:

  • 将所有出现的 index.html 更改为您的 html 文件
  • 更改服务器设置:

    livereload: {
       options: {
         open: true,
         base: [
           '.tmp',
           '<%= yeoman.app %>'
         ]
       }
    }
    

到:

livereload: {
    options: {
      open: 'http://localhost:9000/yourname.html',
      base: [
        '.tmp',
        '<%= yeoman.app %>'
      ]
    }
  },

如果您想使用 yeoman 角度生成器,它们不会更新与 index.html 不同的文件,因为 index.html 在生成器中是硬编码的。只有一个命令行参数 ( --skip-add) 可以防止生成器接触 index.html 文件。

当然。它是开源的。相关部分在文件中:https ://github.com/yeoman/generator-angular/blob/master/script-base.js

Generator.prototype.addScriptToIndex = function (script) {
  try {
    var appPath = this.env.options.appPath;
    var fullPath = path.join(appPath, 'index.html');
    angularUtils.rewriteFile({
      file: fullPath,
      needle: '<!-- endbuild -->',
      splicable: [
        '<script src="scripts/' + script.toLowerCase().replace('\\', '/') + '.js"></script>'
      ]
    });
  } catch (e) {
    console.log('\nUnable to find '.yellow + fullPath + '. Reference to '.yellow + script + '.js ' + 'not added.\n'.yellow);
  }
};

您可以更改名称index.html或提供附加选项来配置名称。

于 2014-01-30T19:41:46.093 回答