Skip to content

Commit

Permalink
Refactor rollup
Browse files Browse the repository at this point in the history
Refactor templates.js
  • Loading branch information
habubey committed Sep 29, 2023
1 parent a69205e commit 0d8382f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 38 deletions.
47 changes: 12 additions & 35 deletions components/doc/common/codeeditor/templates.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const getCRA = (props = {}, template = 'javascript') => {
const sourceFileName = `${path}App${fileExtension}`;
const indexFileName = `${path}index${fileExtension}`;
const unstyled = props.embedded ? ' value={{ unstyled: true, pt: Tailwind }}' : '';
const twImport = props.embedded ? ', Tailwind' : '';

let extFiles = {};

Expand Down Expand Up @@ -71,11 +70,12 @@ const getCRA = (props = {}, template = 'javascript') => {
[`${indexFileName}`]: {
content: `import React from 'react';
import ReactDOM from 'react-dom/client';
import { PrimeReactProvider${twImport} } from 'primereact/api';
import 'primereact/resources/themes/lara-light-indigo/theme.css'; // theme
import { PrimeReactProvider } from 'primereact/api';
${props.embedded ? `import { Tailwind } from 'primereact/passthrough/tailwind';` : ''}
${!props.embedded ? `import 'primereact/resources/themes/lara-light-indigo/theme.css'; // theme` : ''}
${!props.embedded ? `import 'primeflex/primeflex.css'; // css utility` : ''}
import 'primereact/resources/primereact.css'; // core css
import 'primeicons/primeicons.css'; // icons
import 'primeflex/primeflex.css'; // css utility
import 'primeicons/primeicons.css';
import './style.css';
import './flags.css';
import App from './App';
Expand Down Expand Up @@ -105,13 +105,14 @@ root.render(
<meta name="description" content="**${description}** ${PrimeReact.description}" />
<!-- Added to show icons in the editor -->
<link rel="stylesheet" href="https://unpkg.com/primeicons@${dependencies['primeicons'].replace(/[\^|~]/gi, '')}/primeicons.css">
${props.embedded ? '<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">' : ''}
<title>PrimeReact App</title>
</head>
<body>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>`
</body>
</html>`
},
[`${sourceFileName}`]: {
content: sources[template].replace(/^\n/, '')
Expand Down Expand Up @@ -287,37 +288,13 @@ export default function Document() {
`
});

if (props.embedded) {
files['tailwind.config.js'] = {
content: `/** @type{import('tailwindcss')Config} */
module.exports = {
content: [
"./node_modules/primereact/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}`
};

files['postcss.config.js'] = {
content: `module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {}
}
}`
};
}

return { files, dependencies, sourceFileName };
};

const staticStyles = {
global: `html {
font-size: 14px;
}
font-size: 14px;
}
body {
font-family: var(--font-family);
Expand Down
6 changes: 3 additions & 3 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ function addEntry(name, input, output, isComponent = true) {
const onwarn = (warning) => {
if (warning.code === 'MODULE_LEVEL_DIRECTIVE') {
return;
}
}
}
};

const getEntry = (isMinify) => {
return {
Expand All @@ -193,7 +193,7 @@ function addEntry(name, input, output, isComponent = true) {
},
{
format: 'esm',
file: `${output}.esm${isMinify ? '.min' : ''}.mjs`,
file: `${output}.esm${isMinify ? '.min' : ''}.js`,
exports,
banner: "'use client';" // This line is required for SSR.
}
Expand Down

0 comments on commit 0d8382f

Please sign in to comment.