Stefan Mansson
Stefan Mansson

Reputation: 101

Move files to root when my NPM package is installed

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

node_modules

Upvotes: 5

Views: 4274

Answers (2)

Mehdi
Mehdi

Reputation: 7403

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.

Upvotes: 8

Bertrand Martel
Bertrand Martel

Reputation: 45372

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

Upvotes: 0

Related Questions