Skip to content

Instantly share code, notes, and snippets.

View saitonakamura's full-sized avatar
😺

Michael サイトー 中村 Bashurov saitonakamura

😺
View GitHub Profile
@saitonakamura
saitonakamura / next.config.js
Last active February 19, 2018 21:02
Next.js on Github Pages WIP
const isProd = (process.env.NODE_ENV || 'production') === 'production'
module.exports = {
exportPathMap: () => ({
'/': { page: '/' },
}),
assetPrefix: isProd ? '/your-repository-name' : '',
}
@saitonakamura
saitonakamura / next.config.js
Created February 19, 2018 21:02
Next.js on Github Pages
const webpack = require('webpack')
const isProd = (process.env.NODE_ENV || 'production') === 'production'
const assetPrefix = isProd ? '/your-repository-name' : ''
module.exports = {
exportPathMap: () => ({
'/': { page: '/' },
'/page1': { page: '/page1' },
@saitonakamura
saitonakamura / index.js
Last active February 19, 2018 21:09
Next.js on Github Pages link example
import Link from 'next/link'
export default () => (
<div>
<Link href="/page1" as={`${process.env.ASSET_PREFIX}/page1`}>
<a>Go to page</a>
</Link>
Root page
</div>
)
@saitonakamura
saitonakamura / _document.js
Created February 19, 2018 21:14
Next.js on Github Pages _document.js example
import Document, { Head, Main, NextScript } from 'next/document'
export default class MyDocument extends Document {
render() {
return (
<html>
<Head>
<link
rel="stylesheet"
href={`${this.props.__NEXT_DATA__.assetPrefix}/_next/static/style.css`}
@saitonakamura
saitonakamura / Link.jsx
Created February 19, 2018 23:18
Next.js on Github Pages Link wrapper example
0499546ea9c2975b26acb86d2ca81e3448e5c1f6e77816d95a5c7981d9b2e6f806407f3bcae0b19f7e86589dfacd98b066cf0b90c5a83dcfb6fa2256a94b16106f
@saitonakamura
saitonakamura / next.config.js
Last active April 16, 2018 07:14
Next.js Awesome Typescript integration: how to modify Next.js default webpack configuration
module.exports = {
webpack(config, { dev }) {
// modify it!
return config;
}
}
@saitonakamura
saitonakamura / next.config.js
Last active July 17, 2023 08:52
Next.js Awesome Typescript integration: how to add awesome-typescript-loader to Next.js webpack config
module.exports = {
webpack(config, options) {
const { dir, defaultLoaders } = options
config.pageExtensions.push(".ts", ".tsx");
config.resolve.extensions.push(".ts", ".tsx");
config.module.rules.push({
test: /\.tsx?$/,
@saitonakamura
saitonakamura / tsconfig.json
Last active April 16, 2018 07:16
Next.js Awesome Typescript integration: minimal tsconfig.json
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"jsx": "preserve",
"moduleResolution": "node",
}
}
@saitonakamura
saitonakamura / next.config.js
Last active April 16, 2018 07:19
Next.js Awesome Typescript integration: how to add babel integration
module.exports = {
webpack(config, options) {
const { dir, defaultLoaders } = options
config.pageExtensions.push(".ts", ".tsx");
config.resolve.extensions.push(".ts", ".tsx");
// ADDED THIS
// cacheDirectory option is unavailable in case of useBabel option