Skip to content

Commit

Permalink
Merge pull request #3480 from preactjs/render-to-string
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister authored Mar 16, 2022
2 parents a69f287 + 20a668a commit 55f0a84
Show file tree
Hide file tree
Showing 38 changed files with 7,590 additions and 555 deletions.
5 changes: 5 additions & 0 deletions .changeset/lovely-islands-listen.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'preact': minor
---

Add `preact/server` entry to the core package
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ preact-*.tgz
preact.tgz
jsx-csstype.d.ts
.cache
src/preact-render-to-string-tests.d.ts
benchmarks/.v8.modern.js
86 changes: 63 additions & 23 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,38 +15,78 @@ module.exports = function(api) {
rename[name] = mangle.props.props[prop];
}

return {
presets: [
const presets = [];
const plugins = [];

if (process.env.SERVER === 'true') {
presets.push([
'@babel/preset-env',
{
loose: true,
exclude: ['@babel/plugin-transform-typeof-symbol'],
targets: {
node: true
}
}
]);

plugins.push(
[
'@babel/plugin-transform-react-jsx',
{ runtime: 'automatic', importSource: 'preact' }
],
['babel-plugin-transform-rename-properties', { rename }],
[
'@babel/preset-env',
'module-resolver',
{
loose: true,
// Don't transform modules when using esbuild
modules: noModules ? false : 'auto',
exclude: ['@babel/plugin-transform-typeof-symbol'],
targets: {
browsers: [
'Firefox>=60',
'chrome>=61',
'and_chr>=61',
'Safari>=10.1',
'iOS>=10.3',
'edge>=16',
'opera>=48',
'op_mob>=48',
'Samsung>=8.2',
'not dead'
]
root: ['.'],
alias: {
'preact/jsx-dev-runtime': './jsx-runtime/src/index.js',
'preact/jsx-runtime': './jsx-runtime/src/index.js',
'preact/test-utils': './test-utils/src/index.js',
'preact/hooks': './hooks/src/index.js',
'preact/compat': './compat/src/index.js',
preact: './src/index.js'
}
}
]
],
plugins: [
);
} else {
presets.push([
'@babel/preset-env',
{
loose: true,
// Don't transform modules when using esbuild
modules: noModules ? false : 'auto',
exclude: ['@babel/plugin-transform-typeof-symbol'],
targets: {
browsers: [
'Firefox>=60',
'chrome>=61',
'and_chr>=61',
'Safari>=10.1',
'iOS>=10.3',
'edge>=16',
'opera>=48',
'op_mob>=48',
'Samsung>=8.2',
'not dead'
]
}
}
]);

plugins.push(
'@babel/plugin-proposal-object-rest-spread',
'@babel/plugin-transform-react-jsx',
'babel-plugin-transform-async-to-promises',
['babel-plugin-transform-rename-properties', { rename }]
],
);
}

return {
presets,
plugins,
include: ['**/src/**/*.js', '**/test/**/*.js'],
overrides: [
{
Expand Down
13 changes: 2 additions & 11 deletions compat/server.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
/* eslint-disable */
var renderToString;
try {
const mod = require('preact-render-to-string');
renderToString = mod.default || mod.renderToString || mod;
} catch (e) {
throw Error(
'renderToString() error: missing "preact-render-to-string" dependency.'
);
}
const { renderToString } = require('preact/server');

module.exports = {
renderToString: renderToString,
renderToString,
renderToStaticMarkup: renderToString
};
2 changes: 1 addition & 1 deletion compat/server.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export {
renderToString,
renderToString as renderToStaticMarkup
} from 'preact-render-to-string';
} from 'preact/server';
Loading

0 comments on commit 55f0a84

Please sign in to comment.