简体   繁体   English

如何在网站项目和应用程序上使用 webpack

[英]how to use webpack on a website project and app

One part of my project (call it an app) is using react which utilizes webpack.我的项目的一部分(称为应用程序)正在使用利用 webpack 的反应。 Now, I'd like to use webpack on other parts of the site which do not use react.现在,我想在站点的其他不使用反应的部分使用 webpack。 I tried to install webpack in the root folder of the project, but get the errorno -4048, code: 'EPERM' I suspect it has something to do with the fact that webpack is already installed.我试图在项目的根文件夹中安装 webpack,但得到errorno -4048, code: 'EPERM'我怀疑这与 webpack 已经安装的事实有关。 So, the question is if I can use webpack that is already installed to manage other parts of the site?那么,问题是我是否可以使用已经安装的 webpack 来管理站点的其他部分? If yes, I assume that I have to add some key-value pair such as "buildSite": "webpack src/js/site.js dist/bundle.js" Is this the way to go?如果是,我假设我必须添加一些键值对,例如"buildSite": "webpack src/js/site.js dist/bundle.js"这是通往 go 的方式吗?

Sure you can.你当然可以。 running webpack command from npm scripts will search webpack in node_modules.从 npm 脚本运行webpack命令将在 node_modules 中搜索 webpack。

Assuming you are referring to a Monorepository with server and app project you can have a webpack.config.js for each one of your projects.假设您指的是具有服务器和应用程序项目的 Monorepository,您的每个项目都可以有一个webpack.config.js They can even share common configuration.他们甚至可以共享通用配置。

Given this folder structure:鉴于此文件夹结构:

root_folder:
-node_modules
-package.json
-src
--server_project
---server.index.js
---webpack.config.js
--app_project
---app.index.js
---webpack.config.js

You can define the correlating npm scripts in package.json:您可以在 package.json 中定义相关的 npm 脚本:

"scripts": {
   "build_server": "webpack ./src/server_project/webpack.config.js",
   "build_app": "webpack ./src/app_project/webpack.config.js",
   "build": "npm run build_server && npm run build_app"
}

And run:并运行:

npm run build

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在与Webpack捆绑的Angular 1应用程序中使用Bootstrap - How to use Bootstrap in Angular 1 app bundled with Webpack 如何使用Webpack部署Express + React应用 - How to use webpack to deploy an Express + React app 如何使用Webpack 3在打字稿项目中正确使用RxJS 5? - How to properly use RxJS 5 in a typescript project using webpack 3? 如何在 Symfony 项目中使用带有 webpack-encore 的 jQuery? - How to use jQuery with webpack-encore in a Symfony project? 如何在我的Webpack项目中使用Polyglot.js? - How to use Polyglot.js in my Webpack Project? 如何在Create React App中使用Webpack devServer代理 - How to use webpack devServer proxy in create react app 如何在Ionic Version 1应用程序中使用Webpack? (有可能/有替代方案吗?) - How can I use Webpack in an Ionic Version 1 app? (Is it possible/are there alternatives?) 转换旧的应用程序以使用Webpack - Convert old app to use webpack 如何使用简单的“a”标签在现有网站中包含使用 npm 和 webpack 构建的 vuejs 应用程序? - how to include a vuejs app build with npm and webpack in an existing website with a simple 'a' tag? 如何使Webpack在位于项目文件夹外部的js脚本中使用项目的“ node_modules”? - How to make Webpack use project's “node_modules” in js scripts located outside the project folder?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM