未验证 提交 d59858e3 编写于 作者: T Tim Neutkens 提交者: GitHub

Remove example (#9910)

Closes #8935 #8934
上级 d55b4640
# Typings for CSS Modules example
## Deploy your own
Deploy the example using [ZEIT Now](https://zeit.co/now):
[![Deploy with ZEIT Now](https://zeit.co/button)](https://zeit.co/new/project?template=https://github.com/zeit/next.js/tree/canary/examples/with-typings-for-css-modules)
## How to use
### Using `create-next-app`
Execute [`create-next-app`](https://github.com/zeit/next.js/tree/canary/packages/create-next-app) with [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) or [npx](https://github.com/zkat/npx#readme) to bootstrap the example:
```bash
npx create-next-app --example with-typings-for-css-modules with-typings-for-css-modules-app
# or
yarn create next-app --example with-typings-for-css-modules with-typings-for-css-modules-app
```
### Download manually
Download the example:
```bash
curl https://codeload.github.com/zeit/next.js/tar.gz/canary | tar -xz --strip=2 next.js-canary/examples/with-typings-for-css-modules
cd with-typings-for-css-modules
```
Install it and run:
```bash
npm install
npm run dev
# or
yarn
yarn dev
```
Deploy it to the cloud with [now](https://zeit.co/now) ([download](https://zeit.co/download)):
```bash
now
```
## The idea behind the example
This example shows how to generate type declarations for using CSS modules with TypeScript. It uses the [next-css](https://github.com/zeit/next-plugins/tree/master/packages/next-css) plugin and [typings-for-css-modules-loader](https://www.npmjs.com/package/typings-for-css-modules-loader). With additional samples of how to apply using sass, less and stylus.
/// <reference types="next" />
/// <reference types="next/types/global" />
const withCSS = require('@zeit/next-css')
/* With additional configuration on top of CSS Modules */
module.exports = withCSS({
cssModules: true,
cssLoaderOptions: {
camelCase: true,
namedExport: true,
},
webpack(config, options) {
if (!options.isServer) {
/* Using next-css */
for (let entry of options.defaultLoaders.css) {
if (entry.loader === 'css-loader') {
entry.loader = 'typings-for-css-modules-loader'
break
}
}
/* Using next-less */
/*
for (let entry of options.defaultLoaders.less) {
if (entry.loader === 'css-loader') {
entry.loader = 'typings-for-css-modules-loader';
break;
}
}
*/
/* Using next-sass */
/*
for (let entry of options.defaultLoaders.sass) {
if (entry.loader === 'css-loader') {
entry.loader = 'typings-for-css-modules-loader';
break;
}
}
*/
/* Using next-stylus */
/*
for (let entry of options.defaultLoaders.stylus) {
if (entry.loader === 'css-loader') {
entry.loader = 'typings-for-css-modules-loader';
break;
}
}
*/
}
return config
},
})
{
"name": "with-typings-for-css-modules",
"version": "1.0.0",
"license": "ISC",
"scripts": {
"dev": "next",
"build": "next build",
"start": "next start",
"type-check": "tsc"
},
"dependencies": {
"@zeit/next-css": "^1.0.1",
"next": "latest",
"react": "^16.7.0",
"react-dom": "^16.7.0",
"typings-for-css-modules-loader": "^1.7.0"
},
"devDependencies": {
"@types/react": "16.4.16",
"@types/react-dom": "16.0.9",
"typescript": "3.1.3"
}
}
/* With CSS Modules */
import css from '../style.css'
export default () => (
<div className={css.example}>
<p className={css.exampleDescription}>
Hello World, I am being styled using <strong>Typed</strong> CSS Modules!
</p>
</div>
)
.example {
font-size: 50px;
color: papayawhip;
}
.example__description > strong {
color: tomato;
text-transform: uppercase;
font-style: italic;
}
export const example: string
export const example__description: string
export const exampleDescription: string
{
"compilerOptions": {
"allowJs": true,
"alwaysStrict": true,
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
"jsx": "preserve",
"lib": ["dom", "es2017"],
"module": "esnext",
"moduleResolution": "node",
"noEmit": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"skipLibCheck": true,
"strict": true,
"target": "esnext"
},
"exclude": ["node_modules"],
"include": ["**/*.ts", "**/*.tsx"]
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册