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

feat: support preview.config.js using named exports instead of a default export #2030

Merged
merged 3 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@previewjs/config",
"version": "5.0.1",
"version": "5.1.0",
"license": "MIT",
"author": {
"name": "François Wouts",
Expand Down
2 changes: 1 addition & 1 deletion config/src/read-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ async function loadModule(configPath: string, asModule: boolean) {
const module = await import(
`${url.pathToFileURL(configPath).href}?ts=${Date.now()}`
);
return module.default;
return module.default || module;
} else {
// Delete any existing cache so we reload the config fresh.
delete require.cache[require.resolve(configPath)];
Expand Down
2 changes: 1 addition & 1 deletion core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@fwouts/vite-tsconfig-paths": "^4.2.1",
"@previewjs/analyzer-api": "^0.1.2",
"@previewjs/api": "^16.0.1",
"@previewjs/config": "^5.0.1",
"@previewjs/config": "^5.1.0",
"@previewjs/iframe": "^12.0.1",
"@previewjs/serializable-values": "^9.0.1",
"@previewjs/type-analyzer": "^10.0.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "react-test-app-wrapper-custom-esm-named-exports-config",
"license": "MIT",
"private": true,
"type": "module",
"scripts": {
"start": "react-scripts start"
},
"dependencies": {
"@types/node": "^18.16.14",
"@types/react": "^18.2.6",
"@types/react-dom": "^18.2.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "^5.0.1",
"typescript": "^4.9.5"
},
"devDependencies": {
"@babel/core": "^7.21.8",
"@previewjs/config": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const wrapper = {
path: "src/Wrapper.js",
componentName: "Around",
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
name="description"
content="Web site created using create-react-app"
/>
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `pnpm start`.
To create a production bundle, use `npm run build` or `pnpm build`.
-->
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.App {
text-align: center;
}

.App-logo {
height: 40vmin;
pointer-events: none;
}

@media (prefers-reduced-motion: no-preference) {
.App-logo {
animation: App-logo-spin infinite 20s linear;
}
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";
import logo from "./logo.svg";
import "./App.css";

function App() {
return (
<div id="ready" className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
}

export { App };
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const Around = ({ children }) => {
return <div style={{ border: "10px solid #f00" }}>{children}</div>;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import { App } from "./App";

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById("root")
);
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/// <reference types="react-scripts" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": ["src"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"devDependencies": {
"@babel/core": "^7.21.8",
"@previewjs/config": "^4.0.2"
"@previewjs/config": "workspace:*"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
},
"devDependencies": {
"@babel/core": "^7.21.8",
"@previewjs/config": "^4.0.2"
"@previewjs/config": "workspace:*"
}
}
1 change: 1 addition & 0 deletions framework-plugins/react/tests/smoke-tests.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ test.describe.parallel("smoke tests", () => {
"vite-without-svgr": ["src/App.tsx:App"],
"wrapper-custom": ["src/App.tsx:App"],
"wrapper-custom-esm": ["src/App.tsx:App"],
"wrapper-custom-esm-named-exports-config": ["src/App.tsx:App"],
"wrapper-default": ["src/App.tsx:App"],
},
});
Expand Down
Loading
Loading