gruntjs - Yeoman - 多个应用程序,共享依赖项

标签 gruntjs yeoman bower

我是 Yeoman 的新手,我正在开发一个至少有两个应用程序的项目 - 一个用于网站的前端,另一个用于管理面板。它在 Backbone 中,但我认为这部分无关紧要。 我很清楚如何使用 Yeoman 设置单个应用程序。但是,当两个应用程序共享相同的依赖项(即主干、下划线等)时,如何设置两个应用程序。 似乎找不到这个问题的答案。

最佳答案

您可以创建两个应用程序文件夹 - app1 和 app2。依赖项node_modules 和bower_components 将位于根级别。参见下面的结构:

YourApp
  - node_modules
  - bower_components
  - app1
  - app2
  - bower.json
  - package.json
  - GruntFile.js

当您运行 grunt 任务来构建应用程序时。它基本上在 bower.json 中查找关键 appPath。您可以将此键值设置为您要构建的文件夹的名称。 另一种方法是在 GruntFile.js 中进行一些修改,以使用单独的 grunt 任务来构建不同的应用程序文件夹。请参阅下面的代码:

  // Configurable paths for the application
  var appConfig = {
    app: require('./bower.json').appPath || 'app',
    app1: 'app1',  // Added new App1 here.. Similarly you can add multiple keys here.
    dist: 'dist'
  };   

添加了一个新的子任务 livereload1,它将监视 app1 目录中的更改

  livereload1: {
        options: {
          open: true,
          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.app1) // your new appConfig path
            ];
          }
        }
      }

注册一个新的任务app1来构建app1文件夹

 grunt.registerTask('app1', 'Compile then start a connect web server', function (target) {
        grunt.task.run([
          'clean:server',
          'wiredep',
          'concurrent:server',
          'autoprefixer:server',
          'connect:livereload1',
          'watch'
        ]);
      });

同样,您可以为 Test 或 Dist 等创建新任务。

关于gruntjs - Yeoman - 多个应用程序,共享依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25120242/

相关文章:

javascript - 扩展 Angular yeoman 生成器

npm - 在 nupkg 中包含 javascript 和 css 的推荐方法

javascript - Grunt 未找到 "qunit"目标

ruby - compass 路径需要更正

node.js - 如何测试 Grunt 任务?理解和最佳实践

git - Yeoman 生成器 - 创建远程 github 存储库

javascript - Angular-route Bower 下载问题

css - 如何使用 Bower 在 Rails 应用程序中包含自己的 css 文件?

javascript - 如何从复制任务中调用 grunt 提示任务?

express - xdg-打开 : no method available even after installing xdg-utils