【问题标题】:dist folder generated using grunt build not working使用 grunt build 生成的 dist 文件夹不起作用
【发布时间】:2016-05-05 17:16:07
【问题描述】:

我正在开发一个使用 yeoman 创建的 Angular 应用程序,并分别使用 grunt 和 bower 任务执行和依赖管理。

当我使用 grunt serve 运行应用程序时应用程序运行良好,但是当我尝试使用 grunt serve:dist 运行应用程序进行部署时,我在控制台上收到此错误:-

http://localhost:9000/dist/views/pages/login.html404 未找到

然后进入无限循环。我还在这里附上了浏览器控制台截图

有人可以指导我可能是什么错误或从哪里开始调试,因为我对 angular、bower、grunt 和 node 还是很陌生。

如果还有什么需要请告诉我

grunt serve --verbose 输出

E:\workspaces\scfs\sentinal>grunt serve --verbose Initializing Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks. Initializing config...OK Loading "Gruntfile.js" tasks...OK
+ build, default, serve, server, test

Running tasks: serve

Running "serve" task

Loading "grunt-contrib-clean" plugin

Registering "E:\workspaces\scfs\sentinal\node_modules\grunt-contrib-clean\tasks" tasks. Loading "clean.js" tasks...OK
+ clean

Running "clean:server" (clean) task Verifying property clean.server exists in config...OK Files: .tmp -> server Options: force=false, no-write=false Cleaning .tmp...
>> 1 path cleaned.

Loading "grunt-wiredep" plugin

Registering "E:\workspaces\scfs\sentinal\node_modules\grunt-wiredep\tasks" tasks. Loading "wiredep.js" tasks...OK
+ wiredep

Running "wiredep" task

Running "wiredep:app" (wiredep) task Verifying property wiredep.app exists in config...OK Files: scfs/index.html Verifying property wiredep.app.src exists in config...OK Options: src=["scfs/index.html"], ignorePath={}

Running "wiredep:test" (wiredep) task Verifying property wiredep.test exists in config...OK Files: test/karma.conf.js Verifying property wiredep.test.src exists in config...OK Options: devDependencies, src="test/karma.conf.js", ignorePath={}, fileTypes={"js":{"block":{},"detect":{"js":{}},"replace":{"js":"'{{filePath}}',"}}}

Loading "grunt-concurrent" plugin

Registering "E:\workspaces\scfs\sentinal\node_modules\grunt-concurrent\tasks" tasks. Loading "concurrent.js" tasks...OK
+ concurrent

Running "concurrent:server" (concurrent) task Verifying property concurrent.server exists in config...OK Files: [no src] -> server Options: limit=8

Initializing Command-line options: --verbose

Reading "Gruntfile.js" Gruntfile...OK

Registering Gruntfile tasks. Initializing config...OK Loading "Gruntfile.js" tasks...OK
+ build, default, serve, server, test

Running tasks: copy:styles

Loading "grunt-contrib-copy" plugin

Registering "E:\workspaces\scfs\sentinal\node_modules\grunt-contrib-copy\tasks" tasks. Loading "copy.js" tasks...OK
+ copy

Running "copy:styles" (copy) task Verifying property copy.styles exists in config...OK Files: scfs/styles/main.css -> .tmp/styles/main.css Files: scfs/styles/sb-admin-2.css -> .tmp/styles/sb-admin-2.css Files: scfs/styles/timeline.css -> .tmp/styles/timeline.css Options: encoding="utf8", processContent=false, processContentExclude=[], timestamp=false, mode=false Copying scfs/styles/main.css -> .tmp/styles/main.css Reading scfs/styles/main.css...OK Writing .tmp/styles/main.css...OK Copying scfs/styles/sb-admin-2.css -> .tmp/styles/sb-admin-2.css Reading scfs/styles/sb-admin-2.css...OK Writing .tmp/styles/sb-admin-2.css...OK Copying scfs/styles/timeline.css -> .tmp/styles/timeline.css Reading scfs/styles/timeline.css...OK Writing .tmp/styles/timeline.css...OK Copied 3 files

Done, without errors.


Execution Time (2016-01-28 13:01:14 UTC) loading tasks               318ms  ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ 45% loading grunt-contrib-copy  301ms  ¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦ 43% copy:styles                  83ms  ¦¦¦¦¦ 12% Total 703ms

Loading "grunt-postcss" plugin

Registering "E:\workspaces\scfs\sentinal\node_modules\grunt-postcss\tasks" tasks. Loading "postcss.js" tasks...OK
+ postcss

Running "postcss:server" (postcss) task Verifying property postcss.server exists in config...OK Files: .tmp/styles/main.css -> .tmp/styles/main.css Files: .tmp/styles/sb-admin-2.css -> .tmp/styles/sb-admin-2.css Files: .tmp/styles/timeline.css -> .tmp/styles/timeline.css Options: processors=[null], map, diff=false, safe=false Reading .tmp/styles/main.css...OK Reading .tmp/styles/sb-admin-2.css...OK Reading .tmp/styles/timeline.css...OK Writing .tmp/styles/main.css...OK File .tmp/styles/main.css created. Writing .tmp/styles/sb-admin-2.css...OK File .tmp/styles/sb-admin-2.css created. Writing .tmp/styles/timeline.css...OK File .tmp/styles/timeline.css created.
>> 3 processed stylesheets created.

Loading "grunt-contrib-connect" plugin

Registering "E:\workspaces\scfs\sentinal\node_modules\grunt-contrib-connect\tasks" tasks. Loading "connect.js" tasks...OK
+ connect

Running "connect:livereload" (connect) task Verifying property connect.livereload exists in config...OK File: [no files] Options: protocol="http", port=9000, hostname="localhost", base=".", directory=null, keepalive=false, debug=false, livereload=35729, open, useAvailablePort=false, onCreateServer=null, middleware=undefined Started connect web server on http://localhost:9000

Loading "grunt-contrib-watch" plugin

Registering "E:\workspaces\scfs\sentinal\node_modules\grunt-contrib-watch\tasks" tasks. Loading "watch.js" tasks...OK
+ watch

Running "watch" task Waiting... Verifying property watch exists in config...OK Verifying property watch.bower.files exists in config...OK Verifying property watch.js.files exists in config...OK Verifying property watch.jsTest.files exists in config...OK Verifying property watch.styles.files exists in config...OK Verifying property watch.gruntfile.files exists in config...OK Verifying property watch.livereload.files exists in config...OK Live reload server started on port: 35729 Watching bower.json for changes. Watching .tmp for changes. Watching bower_components for changes. Watching dist for changes. Watching node_modules for changes. Watching scfs for changes. Watching test for changes. Watching scfs\scripts\app.js for changes. Watching scfs\scripts\controllers for changes. Watching scfs\scripts\directives for changes. Watching scfs\scripts\services for changes. Watching scfs\scripts\shared for changes. Watching scfs\scripts\app1.js for changes. Watching scfs\scripts\constants.js for changes. Watching scfs\scripts\controllers\chartContoller.js for changes. Watching scfs\scripts\controllers\dashboard for changes. Watching scfs\scripts\controllers\user for changes. Watching scfs\scripts\controllers\form.js for changes. Watching scfs\scripts\controllers\login.js for changes. Watching scfs\scripts\services\auth.resolver.js for changes. Watching scfs\scripts\services\authentication.service.js for changes. Watching scfs\scripts\services\datatable.service.js for changes. Watching scfs\scripts\services\map.service.js for changes. Watching scfs\scripts\services\user.service.js for changes. Watching scfs\scripts\shared\flash.service.js for changes. Watching scfs\scripts\shared\session.js for changes. Watching test\spec\controllers\about.js for changes. Watching test\spec\controllers\main.js for changes. Watching scfs\styles\main.css for changes. Watching scfs\styles\sb-admin-2.css for changes. Watching scfs\styles\timeline.css for changes. Watching Gruntfile.js for changes. Watching .tmp for changes. Watching bower_components for changes. Watching dist for changes. Watching node_modules for changes. Watching scfs for changes. Watching test for changes. Watching scfs\404.html for changes. Watching scfs\bower_components for changes. Watching scfs\images for changes. Watching scfs\js for changes. Watching scfs\scripts for changes. Watching scfs\styles for changes. Watching scfs\views for changes. Watching scfs\index.html for changes. Watching scfs\views\chart.html for changes. Watching scfs\views\dashboard for changes. Watching scfs\views\drivers for changes. Watching scfs\views\pages for changes. Watching scfs\views\settings for changes. Watching scfs\views\ui-elements for changes. Watching scfs\views\unit for changes. Watching scfs\views\user for changes. Watching scfs\views\userType for changes. Watching scfs\views\vehicle for changes. Watching scfs\views\form.html for changes.

GruntFile.js 连接配置:-

connect: {
  options: {
    port: 9000,
    // Change this to '0.0.0.0' to access the server from outside.
    hostname: 'localhost',
    livereload: 35729
  },
  livereload: {
    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.app)
        ];
      }
    }
  },
  test: {
    options: {
      port: 9001,
      middleware: function (connect) {
        return [
          connect.static('.tmp'),
          connect.static('test'),
          connect().use(
            '/bower_components',
            connect.static('./bower_components')
          ),
          connect.static(appConfig.app)
        ];
      }
    }
  },
  dist: {
    options: {
      open: true,
      base: '<%= yeoman.dist %>'
    }
  }
}

【问题讨论】:

  • 尝试运行grunt serve --verbose 并在此处发布命令的结果。您是否检查了dist目录是否包含所有它应该包含的内容?
  • 添加了详细输出,如果我没记错的话,目录包含所有需要的内容,构建连接了 html 文件,因此它们不在目录中
  • 在控制台日志中,URL 包含 scfs 目录。我不确定它应该在这里。您可以发布任务“连接”的配置吗?
  • 我将使用 yo 生成的默认应用程序目录重命名为 scfs,并将 grunt js 中的 appConfig.app 变量值更改为 scfs 和 bower.json 中的 appPath。
  • 另外,项目在 grunt:serve 时运行良好,但使用 grunt build 生成的 dist 文件夹无法正常运行

标签: javascript angularjs node.js build gruntjs


【解决方案1】:

我已经能够找出问题所在。实际上,只要 javascript 代码出现错误,保存所有 html 模板的 $templateCache 就不会被填充。由于我使用的是 chrome,并且由于应用程序的实时重新加载,我无法查看原始错误,因为 login.html html 页面的连续点击使 Chrome 浏览器无响应,并且原始错误回退到 javascript 控制台日志中。

现在,当我在 firefox 中运行 dist folder build 时,我能够在几秒钟内看到错误,然后它也退回到这里。解决该错误后,该应用运行良好。

错误实际上是依赖注入的问题,它在我的一个服务文件中没有正确完成,在 grunt build 缩小任务期间没有得到正确解释并在应用程序启动期间给出错误.

希望这对某人有所帮助!

【讨论】:

    【解决方案2】:

    尝试只执行 grunt 命令,不执行任何操作

    【讨论】:

    • 它运行 jshint 任务时会出现如下警告:- scfs/scripts/services/user.service.js line 11 col 25 'UserService' 在定义之前已使用。 line 27 col 9 内部函数应该列在外部函数的顶部。第 27 行第 24 行“GetAll”在定义之前使用。第 31 行 col 25 'GetById' 在定义之前使用。第 35 行 col 31 'GetByUsername' 在定义之前使用。在定义之前使用了第 39 行第 24 列“创建”。第 43 行 col 24 'Update' 在定义之前使用。
    猜你喜欢
    • 2019-09-12
    • 2021-07-21
    • 1970-01-01
    • 2019-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-02
    • 1970-01-01
    相关资源
    最近更新 更多