javascript - Node.js Concat 反斜杠问题
问题描述
所以我目前正在为一个 Angular 项目设置微前端。在尝试创建要在不同项目之间共享的 polyfill、es5 脚本等包时,由于某种原因,正在创建的目录有反斜杠,导致找不到路径。如果这些是正斜杠,他们会工作得很好,想法?
const fs = require('fs-extra');
const concat = require('concat');
(async function build(){
const prgName = process.argv.slice(2)[0];
if(prgName === '' || prgName === undefined){
console.log("Project name is required as an argument");
}else{
const files_es2015 = [
'./dist/' + prgName + '/polyfill-webcomp-es5.js',
'./dist/' + prgName + '/polyfill-webcomp.js',
'./dist/' + prgName + '/polyfill-es2015.js',
'./dist/' + prgName + '/scripts.js',
'./dist/' + prgName + '/main-es2015.js',
]
await fs.ensureDir('./dist/' + prgName + '/elements');
await concat(files_es2015,'./dist/' + prgName + '/elements/' + prgName + '-elements-es2015.js');
const files_es5 = [
'./dist/' + prgName + '/polyfill-webcomp-es5.js',
'./dist/' + prgName + '/polyfill-webcomp.js',
'./dist/' + prgName + '/polyfill-es2015.js',
'./dist/' + prgName + '/scripts.js',
'./dist/' + prgName + '/main-es5.js',
]
await fs.ensureDir('./dist/' + prgName + '/elements');
await concat(files_es2015,'./dist/' + prgName + '/elements/' + prgName + '-elements-es5.js');
console.log('Done generating bundles for ' + prgName);
}
})()
这将在尝试创建构建时输出以下消息
(node:26344) UnhandledPromiseRejectionWarning: Error: ENOENT: no such file or directory, open 'C:\Code\Project\Code Testing\project-UI-Workspace\dist\classroomApp\polyfill-es2015.js'
(Use `node --trace-warnings ...` to show where the warning was created)
(node:26344) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:26344) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
文件夹设置,从 project-UI-workspace 文件夹中查看。这是在运行脚本之后,因此您可以看到元素文件夹已创建,但由于路径错误而没有任何内容。
解决方案
- 当我尝试将多个 javascript 文件合并到一个文件时,我遇到了同样的问题。通过用双反斜杠替换单反斜杠来修复它。
例如:如果路径是:C:\Users\samplecode.js
将其更改为C:\\Users\\samplecode.js
推荐阅读
- c# - 如何解决 Dapper - UnitOfWork 事务错误
- c# - 有没有办法在 C# 中获取当前剪贴板的信息?
- tomcat - 如何将来自 Tomcat 的请求转发到另一个 Tomcat 服务器?
- spring-boot - 如何在测试过程中做到这一点 H2 不会将数据插入表中
- javascript - 无法使用 Webpack 从 Swiper 导入 CSS,出现错误“模块解析失败:意外字符 '@' 您可能需要适当的加载器”
- media-player - 视频教程注释
- python-3.x - 使用模块(插件)向 python 应用程序添加更多 cli 命令
- google-cloud-platform - GCP 数据流 UDF 输入
- c# - ASP.NET Core 通过 HTTP 接收自定义配置以配置 Kestrel
- spring - 我们可以在同一个项目中同时拥有spring mvc和spring boot吗