Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Feature/storybook default import #18367

Closed
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion examples/with-storybook/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
module.exports = {
stories: ['../stories/*.stories.@(ts|tsx|js|jsx|mdx)'],
addons: ['@storybook/addon-actions', '@storybook/addon-links'],
addons: [
'@storybook/addon-actions',
'@storybook/addon-links',
'@next/plugin-storybook',
],
}
3 changes: 2 additions & 1 deletion examples/with-storybook/components/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sayHello from '@/sayHello'
export default function Home() {
return <div>Hello World</div>
return <div>{sayHello()}</div>
}
9 changes: 9 additions & 0 deletions examples/with-storybook/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// tsconfig.json or jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["utils/*"]
}
}
}
1 change: 1 addition & 0 deletions examples/with-storybook/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
},
"license": "MIT",
"devDependencies": {
"@next/plugin-storybook": "10.0.0",
"@storybook/addon-actions": "6.0.5",
"@storybook/addon-links": "6.0.5",
"@storybook/addons": "6.0.5",
Expand Down
5 changes: 5 additions & 0 deletions examples/with-storybook/utils/sayHello.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Dummy function used demo module paths aliases
// @see https://nextjs.org/docs/advanced-features/module-path-aliases
export default function sayHello() {
return 'Hello World'
}
9 changes: 8 additions & 1 deletion packages/next-plugin-storybook/package.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
{
"name": "@next/plugin-storybook",
"exports": {
"./": "./dist/"
},
"version": "10.0.0",
"repository": {
"url": "vercel/next.js",
"directory": "packages/next-plugin-storybook"
},
"peerDependencies": {
"next": "*"
}
},
"scripts": {
"build": "yarn tsc -d -w -p tsconfig.json"
},
"dependencies": {}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { PHASE_PRODUCTION_BUILD } = require('next/constants')
const { findPagesDir } = require('next/dist/lib/find-pages-dir')
const loadConfig = require('next/dist/next-server/server/config').default
const getWebpackConfig = require('next/dist/build/webpack-config').default
import { PHASE_PRODUCTION_BUILD } from 'next/constants'
import { findPagesDir } from 'next/lib/find-pages-dir'
import loadConfig from 'next/next-server/server/config'
import getWebpackConfig from 'next/build/webpack-config'

const CWD = process.cwd()

Expand All @@ -15,6 +15,7 @@ async function webpackFinal(config) {
target: 'server',
config: nextConfig,
buildId: 'storybook',
rewrites: [],
})

config.plugins = [...config.plugins, ...nextWebpackConfig.plugins]
Expand All @@ -27,7 +28,7 @@ async function webpackFinal(config) {
config.module.rules = [
...config.module.rules.filter((rule) => {
// the rules we're filtering use RegExp for the test
if (!rule.test instanceof RegExp) return true
if (!(rule.test instanceof RegExp)) return true
// use Next.js' built-in CSS
if (rule.test.test('hello.css')) {
return false
Expand Down
13 changes: 13 additions & 0 deletions packages/next-plugin-storybook/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"compilerOptions": {
"outDir": "dist/",
"module": "commonjs",
"sourceMap": true,
"esModuleInterop": true,
"target": "es2015",
"downlevelIteration": true,
"preserveWatchOutput": true
},
"include": ["**/*.ts"],
"exclude": ["node_modules", "dist", "./*.d.ts"]
}