【问题标题】:Ionic add custom script with ionic serve离子添加自定义脚本与离子服务
【发布时间】:2018-06-01 15:17:59
【问题描述】:

我正在通过 CLI 使用 Ionic 3。

在使用离子服务时,我想添加自定义脚本“auth”:

  1. 提示输入用户名和密码

  2. 使用 api 创建 cookie,并在调用每个 API 时使用此 cookie。

我的Gruntfile.js

我在 grunt 中创建了自定义服务器任务:

  1. 提示用户登录

  2. 创建 cookie 并将此 cookie 应用于每个请求。

  3. 能够使用来自 package.json 的 ionic 管理运行。

grunt.registerTask('server', ['checkAuthToken', 'applyAuthToken', 'configureRewriteRules', 'configureProxies']);

"scripts": { "auth": "grunt server", }

现在我想知道如何在 ionic serve 之前导入此身份验证任务,以便我的代理和身份验证工作。

我的package.json中的脚本

我在package.json 中尝试使用下面的 npm-script。它会提示输入用户名、密码并创建 cookie,但是我的代理不起作用,因为我的 grunt 任务是在 ionic watch 之后和 ionic build 之前运行的。

...
"ionic:serve": "ionic-app-scripts serve && grunt server",
"ionic:serve": "grunt server && ionic-app-scripts serve"
...

【问题讨论】:

    标签: ionic-framework gruntjs ionic3


    【解决方案1】:

    您好,如果您有 ionic cli,那么您可以在 package.json 的脚本部分中使用 ionic:build:before

    示例:package.json

    "scripts": {
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve",
        "ionic:build:before": "grunt server"
      }
    

    【讨论】:

      猜你喜欢
      • 2016-06-05
      • 2018-12-08
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多