- Setup react using Webpacker react installer. Then run the typescript installer
bundle exec rails webpacker:install:typescript
yarn add @types/react @types/react-dom- Rename the generated
hello_react.jstohello_react.tsx. Make the file valid typescript and now you can use typescript, JSX with React.
- Setup vue using Webpacker vue installer. Then run the typescript installer
bundle exec rails webpacker:install:typescript- Rename generated
hello_vue.jstohello_vue.ts. - Change generated
config/webpack/loaders/typescript.jsfrom
module.exports = {
test: /\.(ts|tsx)?(\.erb)?$/,
use: [{
loader: 'ts-loader'
}]
}to
module.exports = {
test: /\.(ts|tsx)?(\.erb)?$/,
use: [{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
}]
}and now you can use <script lang="ts"> in your .vue component files.
After you have installed Angular using bundle exec rails webpacker:install:angular
you would need to follow these steps to add HTML templates support:
- Use
yarnto add html-loader
yarn add html-loader- Add html-loader to
config/webpack/environment.js
environment.loaders.append('html', {
test: /\.html$/,
use: [{
loader: 'html-loader',
options: {
minimize: true,
removeAttributeQuotes: false,
caseSensitive: true,
customAttrSurround: [ [/#/, /(?:)/], [/\*/, /(?:)/], [/\[?\(?/, /(?:)/] ],
customAttrAssign: [ /\)?\]?=/ ]
}
}]
})- Add
.htmltoconfig/webpacker.yml
extensions:
- .elm
- .coffee
- .html- Setup a custom
d.tsdefinition
// app/javascript/hello_angular/html.d.ts
declare module "*.html" {
const content: string
export default content
}- Add a template.html file relative to
app.component.ts
<h1>Hello {{name}}</h1>- Import template into
app.component.ts
import { Component } from '@angular/core'
import templateString from './template.html'
@Component({
selector: 'hello-angular',
template: templateString
})
export class AppComponent {
name = 'Angular!'
}That's all. Voila!