Aurelia打字稿/ Webpack骷髅+渐进增强

问题描述 投票:1回答:1

我正在尝试使用progressive enhancement来利用Aurelia的typescript/webpack skeleton功能,但我无法使用文档中显示的示例来使用它。我确定这是因为该示例使用JSPM / SystemJS,但我似乎无法在任何地方找到Webpack示例。这是我目前的情况:

./双人床/hello-world.同时

export class HelloWorld {}

./双人床/hello-world.HTML

<template>
    <h1>Hello World</h1>
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Similique, voluptatem. Amet expedita doloribus itaque explicabo
        ex ducimus temporibus quisquam asperiores eveniet beatae, magni eum fuga reprehenderit obcaecati quasi ipsam minima?</p>
</template>

./双人床/卖弄.同时

import '../static/styles.css';
import 'font-awesome/css/font-awesome.css';
import 'bootstrap/dist/css/bootstrap.css';
import { Aurelia } from 'aurelia-framework';
import { PLATFORM } from 'aurelia-pal';
import * as Bluebird from 'bluebird';

Bluebird.config({ warnings: { wForgottenReturn: false } });

export async function configure(aurelia: Aurelia) {
  aurelia.use
    .defaultBindingLanguage()
    .defaultResources()
    .developmentLogging()
    .globalResources(PLATFORM.moduleName('hello-world'));

  await aurelia.start().then(() => aurelia.enhance())
}

./index.额就是

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title><%- htmlWebpackPlugin.options.metadata.title %></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <base href="<%- htmlWebpackPlugin.options.metadata.baseUrl %>">
    <!-- imported CSS are concatenated and added automatically -->
  </head>
  <body>
    <hello-world></hello-world>

    <% if (htmlWebpackPlugin.options.metadata.server) { %>
    <!-- Webpack Dev Server reload -->
    <script src="/webpack-dev-server.js"></script>
    <% } %>
  </body>
</html>

当我运行npm start来测试应用程序时,我得到的是一个空白页面,其中<hello-world></hello-world>组件位于正文的顶部,但是空的并且没有填充模板html。 Webpack正在输出正确的js文件,所以我不确定它是否与在窗口加载之前尝试运行的js有关,或者是否存在其他问题。

有谁知道这是否可以实现?

webpack aurelia
1个回答
0
投票

在更仔细地阅读文档并获得更多前端精明同事的帮助后,我能够使用manual bootstrapping Aurelia提供的功能(特别是该链接中的“使用Webpack手动引导”部分)。然而,文档仍然是过时的,因为你可以简单地使用aurelia-bootstrapper包,不再需要aurelia-bootstrapper-webpack包,这无论如何都给了我构建错误。

首先,您需要更新webpack.config.js文件的入口节点中的app属性以指向main.ts:

entry: {
    app: ['./src/main'],
    // other properties omitted...
  }

然后使用手动引导代码更新main.ts:

import '../static/styles.css';
import 'font-awesome/css/font-awesome.css';
import 'bootstrap/dist/css/bootstrap.css';
import { Aurelia } from 'aurelia-framework';
import { PLATFORM } from 'aurelia-pal';
import * as Bluebird from 'bluebird';

Bluebird.config({ warnings: { wForgottenReturn: false } });

bootstrap(async (aurelia: Aurelia) => {
  aurelia.use
    .defaultBindingLanguage()
    .defaultResources()
    .developmentLogging()
    .globalResources(PLATFORM.moduleName('hello-world'));

  await aurelia.start()
    .then(() => aurelia.enhance())
    .catch(err => console.log(err))
})

现在应该增强您的组件。

© www.soinside.com 2019 - 2024. All rights reserved.