Tim
Tim

Reputation: 340

how to use jquery after running "npm install jquery"

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?

Upvotes: 3

Views: 2890

Answers (1)

OK sure
OK sure

Reputation: 2656

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.

Upvotes: 3

Related Questions