安装我的 NPM 包后将文件移动到 root

Ste*_*son 4 node.js npm node-modules package.json

我目前有我的 repo https://github.com/Aotik/Blossom,我目前正在处理它。它是一个名为的 NPM 发布包blossom-ui

我的问题是,有没有办法在安装包时将文件移出node_modules/blossom-ui到外部文件夹的根目录中node_modules

所以它看起来像

blossom-ui

  • css/

  • styl/

  • fonts/

  • js/

node_modules

  • ...

Meh*_*hdi 6

这可以postinstall在 npm的脚本中完成。

postinstall每次npm install完成时由 npm 自动执行。

    "scripts": {
            "test": "echo \"Error: no test specified\" && exit 1",
            "postinstall": "cp node_modules/blossom-ui ."
    },
Run Code Online (Sandbox Code Playgroud)

更多信息:npm 站点脚本页面


Ber*_*tel 0

如果你使用grunt,一个简单的复制任务将使它像这样:

copy: {
    vendor: {
        files: [{
            expand: true,
            cwd: 'node_modules/bootstrap/',
            src: ['js/**', 'less/**'],
            dest: 'public/vendor/bootstrap/'
        }]
    }
}
.....
grunt.registerTask('build', ['copy:vendor']);
Run Code Online (Sandbox Code Playgroud)

例如,Drywall 项目使用它来复制引导程序和主干,/public/vendor如上所示。如果你检查它的gruntfile.js

请记住,.gitignore如果您从以下位置复制,则目标文件夹必须存在于您的文件夹中:node_modules