Aurelia Typescript/Webpack 骨架 + 渐进增强
Aurelia Typescript/Webpack Skeleton + Progressive Enhancement
我正在尝试利用 progressive enhancement feature of Aurelia using the typescript/webpack skeleton,但我无法使用文档中显示的示例使其正常工作。我确定这是因为该示例使用的是 JSPM/SystemJS,但我似乎无法在任何地方找到 Webpack 示例。这是我目前拥有的:
./src/hello-world.ts
export class HelloWorld {}
./src/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>
./src/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 } });
export async function configure(aurelia: Aurelia) {
aurelia.use
.defaultBindingLanguage()
.defaultResources()
.developmentLogging()
.globalResources(PLATFORM.moduleName('hello-world'));
await aurelia.start().then(() => aurelia.enhance())
}
./index.ejs
<!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 在 window 加载之前尝试 运行 有关,或者是否存在其他问题。
有谁知道这是否可以实现?
在更仔细地阅读文档并获得更精通前端的同事的帮助后,我能够使用 manual bootstrapping Aurelia 提供的(特别是 "Manual Bootstrapping with Webpack" 部分在 link)。然而,文档仍然过时,因为您可以简单地使用 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))
})
现在你的组件应该得到增强了。
我正在尝试利用 progressive enhancement feature of Aurelia using the typescript/webpack skeleton,但我无法使用文档中显示的示例使其正常工作。我确定这是因为该示例使用的是 JSPM/SystemJS,但我似乎无法在任何地方找到 Webpack 示例。这是我目前拥有的:
./src/hello-world.ts
export class HelloWorld {}
./src/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>
./src/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 } });
export async function configure(aurelia: Aurelia) {
aurelia.use
.defaultBindingLanguage()
.defaultResources()
.developmentLogging()
.globalResources(PLATFORM.moduleName('hello-world'));
await aurelia.start().then(() => aurelia.enhance())
}
./index.ejs
<!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 在 window 加载之前尝试 运行 有关,或者是否存在其他问题。
有谁知道这是否可以实现?
在更仔细地阅读文档并获得更精通前端的同事的帮助后,我能够使用 manual bootstrapping Aurelia 提供的(特别是 "Manual Bootstrapping with Webpack" 部分在 link)。然而,文档仍然过时,因为您可以简单地使用 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))
})
现在你的组件应该得到增强了。