Skip to content

ShellyCWJP/minista

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

109 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

minista

About

minista(ミニスタ)は、React (TSX/JSX)で書けるスタティックサイトジェネレーターです。SaaS の web テンプレートコーディング業務を想定し、ビルド時の納品用データが綺麗(ヒューマンリーダブル)であることを重視しています。CSS と JavaScript は個別に出力されます。

  • ゼロコンフィグで始められる
  • React (TSX/JSX)から 100%静的な HTML を出力
  • CSS と JavaScript を個別に Minify 出力
  • SVG スプライトアイコンを自動生成
  • Next.js 風のディレクトリ構成

How To Use

Automatic

コマンド npm init minista を入力するだけでいくつかのテンプレートから選び始められます。テンプレートはオフィシャル以外にも任意の GitHub パブリックリポジトリに対応していますので、自分用のテンプレートを作っておくと効率的です。

# Use interactive CLI
npm init minista

# Use Official Template
npm init minista -- --template [OFFICIAL_TEMPLATE_NAME]

# Use GitHub Template
npm init minista -- --template [GITHUB_USER]/[REPO_NAME]
npm init minista -- --template [GITHUB_USER]/[REPO_NAME]/path/to/example

Manual

手動でセッティングする場合は minista react react-dom をインストールしてください。

$ npm install --save-dev minista react react-dom
# ----------------------------------------------------
# Directory Example
# ----------------------------------------------------

public # Copy root
src
├── assets
│   └── index.js # Required!
├── components
│   └── layout.js
└── pages # Required!
    ├── about
    │   └── index.js
    └── index.js
//----------------------------------------------------
// Page Example
//----------------------------------------------------

import { render } from "minista" // Required!

const PageHome = () => {
  return (
    <h1>Hello</h1>
  )
}

export default render(<PageHome />) // Required!

Commands

Develop

webpack-dev-server でプレビューします。

# Start
$ minista

# Stop
Press Ctrl+C

Build

納品用にビルド。HTML には js-beautify 処理が施され見やすくなります。

$ minista build

Components

Comment

<Comment text="" /> を使うと React では作りにくい HTML コメントが残せます。

import { render, Comment } from "minista"

const PageHome = () => {
  return (
    <>
      <Comment text="Comment Test" />
      <h1>Hello</h1>
    </>
  )
}

export default render(<PageHome />)
<body>
  <!-- Comment Test -->
  <h1>Hello</h1>
</body>

Sitemap

納品用のサイトマップを簡単に作るコンポーネントを npm で追加可能です。納品物に追加の CSS や JavaScript をバンドルさせません。

Customize

webpack

プロジェクトの root に webpack.config.js を配置することで設定をマージできます。

//----------------------------------------------------
// Example: User > webpack.config.js
//----------------------------------------------------

// No installation required.
const MiniCssExtractPlugin = require("mini-css-extract-plugin")
const CopyPlugin = require("copy-webpack-plugin")

// Example of dev mode
const isDev = process.env.NODE_ENV !== "production"

const webpackConfig = {
  // Merge
  devServer: {
    open: ["/index.html"],
  },
  // Replace
  entry: { custom: "./src/assets/index.js" },
  plugins: [
    // Replace
    new MiniCssExtractPlugin({
      filename: "assets/css/[name].css",
    }),
    // Replace
    new CopyPlugin({
      patterns: [{ from: "./static", to: "./", noErrorOnMissing: true }],
    }),
  ],

  // All optimization is replaced.
  optimization: {
    minimize: !isDev,
    minimizer: [
      /* Replace plugins */
    ],
  },
}

module.exports = webpackConfig

TypeScript

TypeScript .tsx でページを作成する場合はモジュールを追加し tsconfig.json をプロジェクトの root に配置。エントリーポイントとして src/assets/index.ts があれば src/assets/index.js の代わりに使用します。

$ npm install --save-dev typescript @types/react @types/react-dom
{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "baseUrl": ".",
    "allowJs": true,
    "strict": true,
    "noImplicitAny": false,
    "strictNullChecks": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noImplicitReturns": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "isolatedModules": false,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "resolveJsonModule": true,
    "jsx": "react-jsx"
  },
  "include": ["**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules", "dist", "webpack.config.js"]
}
# ----------------------------------------------------
# Directory Example
# ----------------------------------------------------

public # Copy root
src
├── assets
│   └── index.ts (or index.js)  # Required!
├── components
│   └── layout.js
└── pages # Required!
    ├── about
    │   └── index.tsx
    └── index.tsx

Babel

Babel はプロジェクトの root に .babelrc もしくは babel.config.js を配置することで設定を上書きできます。カスタマイズしない場合は以下の設定が適応されます。

// JavaScript
const babelJsxOptions = {
  presets: [
    "@babel/preset-env",
    [
      "@babel/preset-react",
      {
        runtime: "automatic",
      },
    ],
  ],
}

// TypeScript
const babelTsxOptions = {
  presets: [
    "@babel/preset-env",
    [
      "@babel/preset-react",
      {
        runtime: "automatic",
      },
    ],
    ["@babel/preset-typescript"],
  ],
}

PostCSS

PostCSS はゼロコンフィグで以下のプラグインが適応されますが、プロジェクトの root に postcss.config.js を配置することで設定を上書きできます。

module.exports = {
  plugins: [
    "postcss-import",
    "postcss-flexbugs-fixes",
    "postcss-sort-media-queries",
    "postcss-preset-env",
  ],
}

Sass / SCSS

sass-loadersass(または node-sass)を追加することで使えます。

$ npm install --save-dev sass-loader sass

Style only

プロジェクトに JavaScript が全く必要ない場合はエントリーポイントを CSS ファイルに変更します。これにより空の JavaScript ファイルを出力することなく納品用データを生成できます。

//----------------------------------------------------
// Example: User > webpack.config.js
//----------------------------------------------------

const webpackConfig = {
  entry: { bundle: "./src/assets/index.css" },
}

module.exports = webpackConfig

SVG sprite icons

src/assets/icons ディレクトリに SVG ファイルを置くと SVG スプライトアイコンの dist/assets/icons.svg が生成されます。以下のようなコンポーネントを作ることでアイコンを呼び出せます。

// Example: ./src/components/svg-sprite-icon.tsx
export interface SvgSpriteIconProps {
  iconId?: string;
}

export const SvgSpriteIcon = (props: SvgSpriteIconProps) => {
  const { iconId } = props
  return (
    <svg className="icon" role="img">
      <use xlinkHref={`/assets/icons.svg#${iconId}`} />
    </svg>
  )
}
<!-- dist html -->
<svg role="img" class="icon">
  <use xlink:href="/assets/icons.svg#star"></use>
</svg>

Media

Respect

License

  • MIT

Credit

About

Mini static site generator that can be written in React (TSX / JSX) for web coding

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • JavaScript 83.2%
  • TypeScript 6.8%
  • CSS 5.0%
  • SCSS 5.0%