3

Hi I use npm install jquery to install a jQuery for my project.but i find it is located in node_modules\jquery with many unwanted files.

but I just wana put node_modules\jquery\dist\jquery.min.js into static\jquery folder

what is the best and common way? copy and paste manually?

1
  • Do you use a build system such as gulp or grunt? If so, they will let you copy the file or incorporate it in a concatenated script. Commented Jul 19, 2017 at 9:35

1 Answer 1

3

You can use npm to do this. In your package.json, add the following to the scripts key

...
"scripts": {
    "build:jquery": "cp node_modules/jquery/dist/jquery.slim.min.js static/jquery/"
},
...

Then you can run: npm run build:jquery

You can add more build tasks to this section as you need them such as copying images and minifying scripts and css, then chain them together in a single command with npm-run-all:

$ npm install npm-run-all --save-dev

And...

...
"scripts": {
    "build:jquery": "cp node_modules/jquery/dist/jquery.slim.min.js static/jquery/",
    "build:images": "cp -R src/assets/images/ static/images/",
    "build": "npm-run-all -p build:*"
},
...

Then run npm run build

npm is a great build tool and often bypasses the need for an additional build framework such as Gulp or Grunt. It can also handle file watchers and such to rebuild when things are modified automatically.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.