Skip to content

Commit

Permalink
add relative import support
Browse files Browse the repository at this point in the history
  • Loading branch information
tuan2311 committed Aug 6, 2020
1 parent ad77b72 commit 3c66189
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 28 deletions.
2 changes: 2 additions & 0 deletions gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
// You can delete this file if you're not using it

import 'tailwindcss/dist/base.min.css';
import 'tailwindcss/dist/components.css';
import 'tailwindcss/dist/utilities.css';
16 changes: 10 additions & 6 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require('path');

// You can delete this file if you're not using it
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
resolve: {
alias: {
'~': path.resolve(__dirname, 'src'),
},
},
});
};
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"prettier": "2.0.5",
"tailwindcss": "^1.6.2",
"twin.macro": "^1.7.0",
"typescript": "^3.9.7"
"typescript": "^3.9.7",
"typescript-plugin-tw-template": "^2.0.1"
},
"keywords": [
"gatsby"
Expand Down
14 changes: 14 additions & 0 deletions src/components/home/Headline.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import tw, { styled } from 'twin.macro';

const HeadlineContainer = styled.div`
${tw`flex justify-between`}
`;
export default function Headline() {
return (
<HeadlineContainer>
<span>Here</span>
<div>Another one</div>
</HeadlineContainer>
);
}
11 changes: 2 additions & 9 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import React from 'react';
import tw from 'twin.macro';

// or use the shorthand version

const Button = tw.button`
bg-blue-500 hover:bg-blue-800 text-white p-2 rounded
`;
import Headline from '~/components/home/Headline';

const IndexPage = () => (
<div>
<h1>Hi people</h1>
<Button>Activate</Button>
<Headline />
</div>
);

Expand Down
8 changes: 8 additions & 0 deletions src/twin.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'twin.macro';
import styledComponent from '@emotion/styled';
import { css as cssProperty } from '@emotion/core';

declare module 'twin.macro' {
export const css: typeof cssProperty;
export const styled: typeof styledComponent;
}
32 changes: 20 additions & 12 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"jsx": "preserve",
"declaration": true,
"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"noEmit": true,
"isolatedModules": true
},
"exclude": ["node_modules", "public", ".cache"]
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"jsx": "preserve",
"declaration": true,
"strict": true,
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
"noEmit": true,
"skipLibCheck": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"isolatedModules": false,
"plugins": [{ "name": "typescript-plugin-tw-template" }],
"baseUrl": ".",
"paths": {
"~/*": ["./src/*"]
}
},
"exclude": ["node_modules", "public", ".cache"]
}

0 comments on commit 3c66189

Please sign in to comment.