[英]Build a js project with package.json
I've two js projects for say A and B, In the Project A's packge.json I've following scripts 我有两个js项目,分别说A和B,在项目A的packge.json中,我正在跟踪脚本
"scripts": {
"start": "webpack-dev-server --https --content-base dist/",
"doc": "n-clean docs && jsdoc --package package.json -c
./jsdoc.config.json",
"clean": "n-clean dist",
"build:dev": "webpack --config webpack.config.js",
"build:prod": "webpack --config webpack.config.js --env.production",
"build": "npm run clean && npm run build:dev && npm run build:prod && npm run doc"
} }
when I run npm run build , I got a bundle js in dist folder of project A. 当我运行npm run build时,我在项目A的dist文件夹中得到了一个捆绑包js。
In B's project , I've the following package.json for scripts. 在B的项目中,我具有以下用于脚本的package.json。
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"serve": "grunt serve --port=9090 --https=true",
"build": "grunt build --production=true"
} }
So I can build project B by running npm run build. 因此,我可以通过运行npm run build来构建项目B。 But can I build Project B after building Poject A(ie it should create bundle in A's dist folder),with in Project B's package.json by adding commands like "build":"npm run build ../A" along with project B's build.
但是我可以在构建Poject A之后构建Project B(即它应该在A的dist文件夹中创建捆绑包),并在Project B的package.json中通过添加“ build”:“ npm run build ../A”命令与项目B一起添加。建立。 So Please help me how to achieve this.
因此,请帮助我如何实现这一目标。
Yes, you can absolutely build Project B's files into Project A's dist
folder. 是的,您绝对可以将Project B的文件构建到Project A的
dist
文件夹中。
You'll have to modify your webpack's config file, it is typically called webpack.config.js
您必须修改webpack的配置文件,通常称为
webpack.config.js
In Project B's webpack.config
file, you'll have to tell webpack the output path. 在项目B的
webpack.config
文件中,您必须告诉webpack输出路径。 You can do so by adding this line of code: 您可以通过添加以下代码行来实现:
module.exports = {
//...
output: {
path: path.resolve(__dirname, '<Path to Project A dist folder>')
}
};
Hope this helps! 希望这可以帮助!
Edit in response to building Project A in Project B: 根据项目B中的项目A进行编辑:
Yes, you'll need to modify your Project B's webpack.config.js file. 是的,您需要修改Project B的webpack.config.js文件。
You can define multiple entry points in that file as 您可以在该文件中将多个入口点定义为
module.exports = {
entry: {
ProjectA: './path/to/my/entry/fileA.js',
ProjectB: './path/to/my/entry/fileB.js',
}
};
Likely you can copy the entry point from your ProjectA's webpack.config.js file into Project B's. 可能您可以将入口点从ProjectA的webpack.config.js文件复制到Project B的文件中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.