[英]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.