Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/typescript app template #96

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/typescript/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "x0-typescript-example",
"private": true,
"scripts": {
"start": "x0 pages",
"build": "x0 build pages"
},
"dependencies": {
"@compositor/x0": "^5.0.0",
"rebass": "^2.0.0-2",
"ts-loader": "^4.5.0"
}
}
9 changes: 9 additions & 0 deletions examples/typescript/pages/_app.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from "react";
import { Box, Heading, Provider } from "rebass";

export default ({ render }: { render: any }) => (
<div>
Custom-App-Wrapper created with Typescript
{render()}
</div>
);
9 changes: 9 additions & 0 deletions examples/typescript/pages/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Provider, Box, Heading } from 'rebass'

# Hello MDX with custom TypeScript App

<Provider>
<Box px={2} py={3}>
<Heading>Hello</Heading>
</Box>
</Provider>
13 changes: 13 additions & 0 deletions examples/typescript/pages/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* It is necessary to add the ts-loader for .tsx files
*/
module.exports = {
resolve: {
extensions: [".js", "md", "mdx", "jsx", ".ts", ".tsx"],
},
module: {
rules: [
{ test: /\.tsx?$/, loader: "ts-loader" }
]
}
}
15 changes: 15 additions & 0 deletions examples/typescript/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"lib": ["es5", "es6"],
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"jsx": "react",
},
"exclude": [
"node_modules"
]
}
4 changes: 2 additions & 2 deletions src/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import ScrollTop from './ScrollTop'
import CenteredLayout from './CenteredLayout'

const IS_CLIENT = typeof document !== 'undefined'
const req = require.context(DIRNAME, true, /\.(js|md|mdx|jsx)$/)
const req = require.context(DIRNAME, true, /\.(js|md|mdx|jsx|tsx)$/)

const { filename, basename = '', disableScroll } = OPTIONS

Expand All @@ -42,7 +42,7 @@ const initialComponents = getComponents(req)
const DefaultApp = props => props.children

const Router = IS_CLIENT ? BrowserRouter : StaticRouter
const appPath = req.keys().find(key => key === './_app.js')
const appPath = req.keys().find(key => key.match(/_app\.(js|jsx|tsx)/g))
const App = appPath ? (req(appPath).default || req(appPath)) : DefaultApp

export const getRoutes = async (components = initialComponents) => {
Expand Down