[英]mvc bundling and relative css image when website is deployed to an application
[英]Aurelia bundling fails when using relative import path
我正在使用aurelia与typescript,我想避免使用相对导入路径,如:
import { DialogBox } from '../../resources/elements/dialog-box';
反而
import { DialogBox } from 'resources/elements/dialog-box';
我修改了tsconfig.json所以编译器中加入的baseUrl和路径这样的处理相对路径:
"compilerOptions": {
"sourceMap": true,
"target": "es5",
"module": "amd",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"lib": ["es2015", "dom"],
"baseUrl": ".",
"paths": {
"*":["src/*"]
}
} ...
但是当我运行cli的命令'au run --watch'时,我可以看到所有步骤都正常工作,而writeBundle步骤在跟踪某些文件时失败:
Starting 'processMarkup'...
Starting 'processCSS'...
Starting 'configureEnvironment'...
Finished 'configureEnvironment'
Starting 'buildTypeScript'...
Finished 'processCSS'
Finished 'processMarkup'
Finished 'buildTypeScript'
Starting 'writeBundles'...
该过程失败,并出现以下错误:
Tracing resources/elements/dialog-box...
{ uid: 11,
name: 'writeBundles',
branch: false,
error:
{ [Error: ENOENT: no such file or directory, open 'C:\...\src\resources\elements\dialog-box.js']
errno: -4058,
奇怪的是:有其他文件使用非相对路径引用,并且捆绑器不会失败。
另一个奇怪的事情是:如果我使用观察者离开相对路径和捆绑,一切正常。 然后,如果我从有问题的导入中删除相对'../../' ,我会得到一个捆绑警告,但无论如何一切都有效......
知道我可能做错了什么吗?
编辑修改:
我只是说明为什么有些文件似乎捆绑在一起而有些文件却没有。 我注意到所有具有“root-relative”导入但未失败的文件实际上是从具有相对路径的其他文件导入的。 所以我想捆绑者会从那里找到它们。 这解决了一件事,但基本问题仍然存在:当存在“根相对”导入时,aurelia-cli无法捆绑...
编辑解决方案:感谢Sinan Bolel的解决方案,通过更新一些软件包解决了相对路径问题:
npm i -D gulp-typescript@^3.1.5 typings@^2.1.0 aurelia-tools@^1.0.0
之后我得到的语义错误来自一些仍然安装且不需要的打字,以及将打字稿作为本地npm包以及全局安装。 我卸载了它们,所有错误都消失了。
npm uninstall @types/es6-promise
npm uninstall @types/es6-collections
npm uninstall typescript
看看这个Gist示例 ,其中:
src/lib/init.ts
创建了一个类Init
import init from 'lib/init'
src/main.ts
import init from 'lib/init'
而没有相对路径 main.ts
更改为import environment from 'environment'
而不是from './environment'
- 这也适用。
使用CLI生成的原始tsconfig
,我的构建失败并显示错误:
src/main.ts(3,18): error TS2307: Cannot find module 'lib/init'.
(无效)建议:
在tsconfig中,您可以尝试:
a)在compilerOptions.paths
添加./
提前src
(这解决了我机器上的问题)
paths: {"*": ["./src/*"]}
^
b)添加filesGlob
"filesGlob": [
"./src/**/*.ts",
"./test/**/*.ts",
"./typings/index.d.ts",
"./custom_typings/**/*.d.ts"
],
编辑:以前的建议不起作用,如何更新包:
npm i -D gulp-typescript@^3.1.5 typings@^2.1.0 aurelia-tools@^1.0.0
请参阅https://github.com/aurelia/cli/issues/494#issuecomment-282103289中的结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.