Coder Social home page Coder Social logo

gregoryforel / react-scripts-ts-antd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from szzzzz/react-scripts-ts-antd

0.0 2.0 0.0 250 KB

scripts for create-react-app base on react-scripts-ts

JavaScript 93.74% HTML 1.44% CSS 0.52% TypeScript 4.30%

react-scripts-ts-antd's Introduction

Create React apps (with Typescript and antd) with no build configuration.

base on [email protected]

Usage

create a new project with create-react-app

create-react-app myapp --scripts-version=react-scripts-ts-antd

Features

Include ts-import-plugin for importing components on demand.

// source
import { Card } from 'antd';

// output
import Card from 'antd/lib/card';
import Card from 'antd/lib/card/style/index.less';

You can rewire your webpack configurations without eject.

// You can get all default loads
const { loaders } = require('react-scripts-ts-antd');

Support scss and less

  • use less-loader for less.
  • use precss for scss.

Turn on some options of compileOptions in tsconfig.json.

// tsconfig.json
{
    "allowSyntheticDefaultImports": "true",
    "experimentalDecorators": "true"
}

Tips

How to avoid importing styles twice

If you want to customize theme by overriding less variables like below.

// index.less
@import "~antd/dist/antd.less";
@primary-color: #000;

You have imported all styles and ts-import-plugin will import styles again. So you need to reset ts-loader options by modifying config-overrides.js to avoid importing styles twice.

// config-overrides.js
const { getLoader } = require("react-app-rewired");
const tsImportPluginFactory = require('ts-import-plugin');

module.exports = function override(config, env) {

  // get tsloader
  const tsloader = getLoader(
    config.module.rules,
    rule => String(rule.test) == String(/\.(ts|tsx)$/)
  );

  // set new options
  tsloader.options = {
    transpileOnly: true,
    getCustomTransformers: () => ({
      before: [
        tsImportPluginFactory([
          {
            libraryName: 'antd',
            libraryDirectory: 'lib',
          },
          {
            libraryName: 'antd-mobile',
            libraryDirectory: 'lib',
          }
        ])
      ]
    })
  }
  return config;
};

antd package will be installed automatically.If you need antd-mobile, install it manually.

react-scripts

This package includes scripts and configuration used by Create React App.
Please refer to its documentation:

  • Getting Started โ€“ How to create a new app.
  • User Guide โ€“ How to develop apps bootstrapped with Create React App.

react-scripts-ts-antd's People

Contributors

engsshi avatar szzzzz avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.