diff --git a/.gitignore b/.gitignore index 40b878d..fd74315 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -node_modules/ \ No newline at end of file +node_modules/ +dist/ \ No newline at end of file diff --git a/index.html b/index.html new file mode 100644 index 0000000..cffbde8 --- /dev/null +++ b/index.html @@ -0,0 +1,14 @@ + + + + + + demo + + + +
+ + + + \ No newline at end of file diff --git a/src/components/Hello.tsx b/src/components/Hello.tsx new file mode 100644 index 0000000..5e96e88 --- /dev/null +++ b/src/components/Hello.tsx @@ -0,0 +1,28 @@ +import * as React from 'react'; + +export interface Props { + name: string; + enthusiasmLevel?: number; +} + +export default class Hello extends React.Component { + render() { + const { name, enthusiasmLevel = 1 } = this.props; + + if (enthusiasmLevel <= 0) { + throw new Error('You could be a little more enthusiastic. :D'); + } + + return ( +
+
+ Hello {name + getExclamationMarks(enthusiasmLevel)} +
+
+ ); + } +} + +function getExclamationMarks(numChars: number) { + return Array(numChars + 1).join('!'); +} \ No newline at end of file diff --git a/src/index.tsx b/src/index.tsx new file mode 100644 index 0000000..4de93dc --- /dev/null +++ b/src/index.tsx @@ -0,0 +1,9 @@ +import * as React from "react"; +import * as ReactDOM from "react-dom"; + +import Hello from "./components/Hello"; + +ReactDOM.render( + , + document.getElementById('root') as HTMLElement +); \ No newline at end of file diff --git a/webpack.common.config.js b/webpack.common.config.js new file mode 100644 index 0000000..2c4aeee --- /dev/null +++ b/webpack.common.config.js @@ -0,0 +1,24 @@ +module.exports = { + entry: "./src/index.tsx", + output: { + filename: "bundle.js", + path: __dirname + "/dist" + }, + + devtool: "source-map", + + resolve: { + extensions: [".ts", ".tsx", ".js", ".json"] + }, + + module: { + rules: [ + { test: /\.tsx?$/, loader: "ts-loader" }, + + { enforce: "pre", test: /\.js$/, loader: "source-map-loader" } + ] + }, + + plugins: [ + ], +}; \ No newline at end of file