如何在NPM脚本中输出JS/JSON [英] How to output JS/JSON in NPM Script

查看:275
本文介绍了如何在NPM脚本中输出JS/JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最后一个问题- npm版本脚本可以访问package.json中的新版本"

如何从NPM脚本输出JS/JSON. npm version之后,我将其写到一个JS/JSON文件中,并在Angular中进行导入,其导入方式类似于我在本文底部编写的内容

How do you output JS / JSON from an NPM script. After an npm version I am writing that out to a JS / JSON file to be picked up in Angular with an import like what I've written at the bottom of this post

我尝试了以下这些变化:

I tried these variations of the following:

"version": "version=$(git tag | head -1); echo \"{version:$version}\" > client/src/app/config-from-npm.json",

  • 在所有情况下都用单引号(')而不是双引号()
  • echo '\{version:...-错误的意外令牌{在JSON中
  • echo '%7Bversion:...-输出'%7Bversion ...'
  • echo '%7Bversion:...-输出'{ version ...'
    • single quote (') instead of double (") in all cases
    • echo '\{version:... - error Unexpected token { in JSON
    • echo '%7Bversion:... - outputs '%7Bversion ...'
    • echo '%7Bversion:... - outputs '{version ...'
    • 我要实现的目标以及如何使用它:

      What I'm trying to achieve and how it will be used:

       export var config = {
           version: v1.0.0
       }
      
       ----
      
       import { config } from './config';
      

      如果我在JS/JSON问题中没有解决此"{"问题,我将把版本号写入文件并读入.整整齐齐!

      If I don't work out this '{' in JS / JSON problem I will just write the version number to file and read in. Nowhere near as neat!

      推荐答案

      是,我知道了. Unicode字符实体- https://unicode-table.com/en/#007B

      Yipee, I worked it out. Unicode character entities - https://unicode-table.com/en/#007B

      在它的'{'带有'U + 007B'的地方,我使用了'\ u007B'.

      Where it has 'U+007B' for '{', I used '\u007B'.

      甜!

      这篇关于如何在NPM脚本中输出JS/JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆