Skip to content

Commit

Permalink
Add example.
Browse files Browse the repository at this point in the history
  • Loading branch information
losfair committed Mar 2, 2022
1 parent e0638d2 commit 27f4b07
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 0 deletions.
34 changes: 34 additions & 0 deletions examples/modularize-imports/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# next.js
/.next/
/out/

# production
/build

# misc
.DS_Store
*.pem

# debug
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# local env files
.env.local
.env.development.local
.env.test.local
.env.production.local

# vercel
.vercel
27 changes: 27 additions & 0 deletions examples/modularize-imports/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Modularize Imports Example

This example shows how to use the `modularizeImports` config option.

## Preview

Preview the example live on [StackBlitz](http://stackblitz.com/):

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/vercel/next.js/tree/canary/examples/modularize-imports)

## Deploy your own

Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=next-example):

[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/git/external?repository-url=https://github.com/vercel/next.js/tree/canary/examples/modularize-imports&project-name=modularize-imports&repository-name=modularize-imports)

## How to use

Execute [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app) with [npm](https://docs.npmjs.com/cli/init) or [Yarn](https://yarnpkg.com/lang/en/docs/cli/create/) to bootstrap the example:

```bash
npx create-next-app --example modularize-imports modularize-imports-app
# or
yarn create next-app --example modularize-imports modularize-imports-app
```

Deploy it to the cloud with [Vercel](https://vercel.com/new?utm_source=github&utm_medium=readme&utm_campaign=next-example) ([Documentation](https://nextjs.org/docs/deployment)).
3 changes: 3 additions & 0 deletions examples/modularize-imports/components/halves/LeftHalf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function LeftHalf() {
return <span>Modularize</span>
}
3 changes: 3 additions & 0 deletions examples/modularize-imports/components/halves/RightHalf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function RightHalf() {
return <span>Imports</span>
}
5 changes: 5 additions & 0 deletions examples/modularize-imports/components/halves/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import LeftHalf from './LeftHalf'
import RightHalf from './RightHalf'

// Remove the exports here so that we can verify that `modularize-imports` is working.
// export { LeftHalf, RightHalf };
9 changes: 9 additions & 0 deletions examples/modularize-imports/next.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module.exports = {
experimental: {
modularizeImports: {
'../components/halves': {
transform: '../components/halves/{{ member }}',
},
},
},
}
13 changes: 13 additions & 0 deletions examples/modularize-imports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "latest",
"react": "^17.0.2",
"react-dom": "^17.0.2"
}
}
10 changes: 10 additions & 0 deletions examples/modularize-imports/pages/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { LeftHalf, RightHalf } from '../components/halves'

const Index = () => (
<div>
<LeftHalf />
<RightHalf />
</div>
)

export default Index

0 comments on commit 27f4b07

Please sign in to comment.