问题
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