An open API service indexing awesome lists of open source software.

https://github.com/zaaksam/koc-loader

Knockout component loader for webpack
https://github.com/zaaksam/koc-loader

knockout webpack-loader

Last synced: 5 months ago
JSON representation

Knockout component loader for webpack

Awesome Lists containing this project

README

          

# koc-loader

Knockout component loader for webpack

[中文说明示例](https://my.oschina.net/zaaksam/blog/1574629)

You can write component file like Vue:

hello.koc

```html

import ko from "knockout";

export default class Component {
info: KnockoutObservable<string>;

constructor(params: any) {
this.info = ko.observable("hello koc-loader");
}
}

```

Webpack.config.js:

```js
{
module: {
resolve: {
extensions: ['.ts', '.js', '.koc']
},
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
exclude: /node_modules/,
options: {
appendTsSuffixTo: [/\.koc$/]
}
},
{
test: /\.koc$/,
loader: 'koc-loader'
}
]
}
}
```

app.ts (app.js)

```ts
import ko from 'knockout'
import Hello from './hello.koc'

ko.components.register('hello', Hello)

ko.applyBindings()
```

index.html

```html




```

koc.d.ts

```ts
///

declare module "*.koc" {
const koc: KnockoutComponentTypes.Config
export default koc
}
```

Thanks:
* [san-loader](https://github.com/ecomfe/san-loader)
* [vue-loader](https://github.com/vuejs/vue-loader)