Move files to root when my NPM package is installed

故事扮演 提交于 2020-06-26 04:48:51

问题


I currently have my repo https://github.com/Aotik/Blossom which I'm working on at the moment. It is a NPM published package named blossom-ui

My question is, is there a way to move the files out of node_modules/blossom-ui into the root of the folder outside node_modules when the package is installed?

So it would look something like

blossom-ui

  • css/

  • styl/

  • fonts/

  • js/

node_modules

  • ...

回答1:


This can be done in a postinstall script in npm.

postinstall is executed automatically by npm each time an npm install finishes.

    "scripts": {
            "test": "echo \"Error: no test specified\" && exit 1",
            "postinstall": "cp node_modules/blossom-ui ."
    },

more info: npm site scripts page.




回答2:


If you use grunt, a simple copy task will make it like this :

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

For instance Drywall project use it to copy bootstrap & backbone to /public/vendor like above. If you check its gruntfile.js.

Keep in mind that your destination folder must be present in your .gitignore if you copy from node_modules



来源:https://stackoverflow.com/questions/38544993/move-files-to-root-when-my-npm-package-is-installed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!