【问题标题】:Why does tns run android work but when I add --bundle it does not为什么 tns 运行 android 工作,但是当我添加 --bundle 它没有
【发布时间】:2018-09-18 17:22:46
【问题描述】:

我正在尝试使用这些说明https://docs.nativescript.org/performance-optimizations/bundling-with-webpack 在我的 nativescript 应用程序中启动和运行 webpack。

命令 tns run android 运行良好,但是当我尝试运行 tns run android --bundle 时,一切都变得混乱了。

我收到的所有错误消息都是一样的,其中一个看起来像这样

ERROR in ./pages/settings/settings.component.ts
Module not found: Error: Can't resolve './pages/settings/settings.html' in 
'C:\Users\stull\Desktop\forritun\SecondLudusApp\app\pages\settings'
 @./pages/settings/settings.component.ts 171:22-63
 @./app.routing.ts
 @./app.module.ts
 @./main.ts

最后我收到了这条消息

Webpack compilation complete.
Unable to apply changes on device: "devicename". Error is: Executing webpack 
failed with exit code 2..
Executing after-watch hook from "path"
Stopping tsc watch
Executing after-watch hook from "path"

有没有人遇到过类似的问题并设法解决了?

如果有帮助,这也是我的 tsconfig.json 文件

{
  "compilerOptions": {
    "target": "es5",
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "noEmitHelpers": false,
    "noEmitOnError": true,
    "lib": [
        "es6",
        "es5",
        "dom",
        "es2015.iterable"
    ],
    "baseUrl": ".",
    "paths": {
        "*": [
            "./node_modules/tns-core-modules/*",
            "./node_modules/*"
        ]
    }
  },
  "exclude": [
    "node_modules",
    "platforms",
    "**/*.aot.ts"
  ]
}

【问题讨论】:

  • 写一个更具描述性的标题

标签: webpack


【解决方案1】:

我发现了问题所在。

使用 tns run android 运行允许我这样做

templateUrl: "pages/something/something.html"

用 webpack 运行不接受这种写法。 它接受这个版本

templateUrl: "./something.html"

对于我从另一个组件中使用的 css 文件,我必须这样做

styleUrls: ["./../otherComponent/otherComponent.html"]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-24
    相关资源
    最近更新 更多