【问题标题】:NPM/React: copyfiles not running correctlyNPM/React:copyfiles 没有正确运行
【发布时间】:2019-02-16 13:44:10
【问题描述】:

Django 2.0, Node.js 8.11.4

我有一个格式为 djanog 的项目:

reactify/
└── src/
    ├── reactify-ui/
    |   ├── build/
    |   |   └── static/
    |   |       └── js/
    |   |           └── main.3425.js
    |   └── package.json
    └── staticfiles/
        └── js/
            └── reactify-django-us.js

我想用\reactify\src\reactify-ui\build\static\js\*中的内容替换\reactify\src\staticfiles\js的内容

我的packages.json 看起来像这样

    "scripts": {
     ...
    "copy-build-js": "copyfiles -f 'build/static/js/*.js' '../staticfiles/js/'",,
     ...
  }

当我运行 npm copy-build-js 时,我得到以下输出:

> reactify-ui@0.1.0 copy-build-js    C:\Users\Owner\dev\reactifydjango\src\reactify-ui
> copyfiles -f 'build/static/js/*.js' '../staticfiles/js/'

看起来它可以工作,但是当我检查目标位置../staticfiles/js/ 中的文件时,它并没有改变。 我通过

验证它
changing the file before I run the command,
do an `ls -lrth` to get the timetamp, 
wait a minute so the timestamp changes, 
run the command `npm copy-build-js`,  
and then doing an `ls -lrth` on the target location and seeing that the timestamp isn't post hasn't changed.
I also look at the file and it is the same.

为什么复制文件不起作用?

【问题讨论】:

    标签: reactjs npm npm-run


    【解决方案1】:

    你的结构是正确的,但是copyfiles 包有一些你错过的怪癖。将此用作您的脚本:

    "copy-build-js": "del /F \"../staticfiles/js\" && copyfiles -E -f \"./build/static/js/*.js\" ../staticfiles/js"

    这里的双引号是必需的,所以你需要在每个之前添加黑色斜线来转义它们。

    copyfiles 包没有替换目录中所有文件的选项,即使文件名不存在,所以首先你必须运行del /F \"../staticfiles/js\" 来删除src/staticfiles/js 目录中的所有文件。此命令假定您使用的是 Windows。

    然后你运行copyfiles -E -f \"./build/static/js/*.js\" ../staticfiles/js。您错过的是,在此包 (*) 中使用通配符/glob 时,您必须 double 引用该位置。如果某个位置没有通配符,则根本不需要引号。我添加了-E 标志,如果不复制文件会引发错误,这可能会在以后为您省去麻烦。

    【讨论】:

    • 我在 Windows 上。这很棒!是否有强制它在不请求许可的情况下删除目录中的文件?
    猜你喜欢
    • 2022-06-10
    • 2022-07-24
    • 2015-12-31
    • 1970-01-01
    • 2020-12-01
    • 2018-08-03
    • 2015-08-21
    • 2016-09-26
    • 1970-01-01
    相关资源
    最近更新 更多