在服务器上使用npm安装库

时间:2023-01-18 00:12:15

when i want to use some library, such as Croppie, i should install it by using npm or Bower:

当我想使用一些库,比如Croppie时,我应该使用npm或Bower来安装它:

npm install croppie

bower install croppie

As i am using a server, i dont know where is should install it. On the server? in the wordpress files? or in the same folder that contains JS file for this library.

因为我正在使用服务器,我不知道应该在哪里安装它。在服务器上?在wordpress文件?或者在包含此库的JS文件的同一文件夹中。

Thanks a lot

非常感谢

3 个解决方案

#1


0  

Basically you need to add script in your wordpress web app. So there are multiple ways to do so.

基本上你需要在你的wordpress web应用程序中添加脚本。所以有多种方法可以做到这一点。

1) Add <script src="https://raw.githubusercontent.com/Foliotek/Croppie/master/croppie.min.js" />. It's better either you download this file in your file system or add a CDN link of Croppie.

1)添加

2) If you have bower.json configured in your project you can use bower install croppie and then link it in your index.php (root file)

2)如果您在项目中配置了bower.json,则可以使用bower install croppie,然后将其链接到index.php(根文件)中

#2


0  

If you just have copied your project over to your server, you should have a package.json file, which contains all libraries you used. (Given you saved it via npm install croppie --save or npm install croppie --save-dev)

如果您刚将项目复制到服务器,则应该有一个package.json文件,其中包含您使用的所有库。 (鉴于你通过npm install croppie保存了它--save或npm install croppie --save-dev)

Then you can just go into your directory which contains the package.json and run npm install.

然后你可以进入包含package.json的目录并运行npm install。

If you ever install a library which you would like to use without a project, you can install it globally with npm install libraryName -g, thus making it available on the command line.

如果您在没有项目的情况下安装了要使用的库,则可以使用npm install libraryName -g在全局安装它,从而使其在命令行中可用。

#3


0  

In general, if you develop locally and deploy to a server, you should install dependencies locally, in /wp-content/themes/(your-theme)/ and don't upload them to your web server along with the rest of the site. The .bowerrc file, placed in the theme directory, should include the target directory in which bower will place the dependencies you've required:

通常,如果您在本地开发并部署到服务器,则应在/ wp-content / themes /(your-theme)/本地安装本地依赖项,并且不要将它们与站点的其余部分一起上载到Web服务器。放置在主题目录中的.bowerrc文件应包含目标目录,bower将在其中放置您所需的依赖项:

{
"directory": "bower_components"
}

Then you'd want to bundle those dependencies in css/js etc. directories within the theme and deploy those. .gitignore the bower_components directory or just don't FTP that directory up, depending on how you do things.

然后你想要在主题中的css / js等目录中捆绑这些依赖项并部署它们。 .gitignore bower_components目录或者只是不要FTP该目录,具体取决于你的工作方式。

#1


0  

Basically you need to add script in your wordpress web app. So there are multiple ways to do so.

基本上你需要在你的wordpress web应用程序中添加脚本。所以有多种方法可以做到这一点。

1) Add <script src="https://raw.githubusercontent.com/Foliotek/Croppie/master/croppie.min.js" />. It's better either you download this file in your file system or add a CDN link of Croppie.

1)添加

2) If you have bower.json configured in your project you can use bower install croppie and then link it in your index.php (root file)

2)如果您在项目中配置了bower.json,则可以使用bower install croppie,然后将其链接到index.php(根文件)中

#2


0  

If you just have copied your project over to your server, you should have a package.json file, which contains all libraries you used. (Given you saved it via npm install croppie --save or npm install croppie --save-dev)

如果您刚将项目复制到服务器,则应该有一个package.json文件,其中包含您使用的所有库。 (鉴于你通过npm install croppie保存了它--save或npm install croppie --save-dev)

Then you can just go into your directory which contains the package.json and run npm install.

然后你可以进入包含package.json的目录并运行npm install。

If you ever install a library which you would like to use without a project, you can install it globally with npm install libraryName -g, thus making it available on the command line.

如果您在没有项目的情况下安装了要使用的库,则可以使用npm install libraryName -g在全局安装它,从而使其在命令行中可用。

#3


0  

In general, if you develop locally and deploy to a server, you should install dependencies locally, in /wp-content/themes/(your-theme)/ and don't upload them to your web server along with the rest of the site. The .bowerrc file, placed in the theme directory, should include the target directory in which bower will place the dependencies you've required:

通常,如果您在本地开发并部署到服务器,则应在/ wp-content / themes /(your-theme)/本地安装本地依赖项,并且不要将它们与站点的其余部分一起上载到Web服务器。放置在主题目录中的.bowerrc文件应包含目标目录,bower将在其中放置您所需的依赖项:

{
"directory": "bower_components"
}

Then you'd want to bundle those dependencies in css/js etc. directories within the theme and deploy those. .gitignore the bower_components directory or just don't FTP that directory up, depending on how you do things.

然后你想要在主题中的css / js等目录中捆绑这些依赖项并部署它们。 .gitignore bower_components目录或者只是不要FTP该目录,具体取决于你的工作方式。