Skip to content

Commit

Permalink
upgrade to next 12
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Nov 2, 2021
1 parent fb80d64 commit 3ace276
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 51 deletions.
39 changes: 1 addition & 38 deletions test/fixture/next-webpack5/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,12 @@ const withPrefresh = require('@prefresh/next');
const path = require('path');

const config = {
experimental: {
modern: true,
polyfillsOptimization: true,
},
future: {
webpack5: true,
},
webpack(config, { dev, isServer }) {
const splitChunks = config.optimization && config.optimization.splitChunks;
if (splitChunks && isServer && splitChunks.cacheGroups) {
const cacheGroups = splitChunks.cacheGroups;
const preactModules = /[\\/]node_modules[\\/](preact|preact-render-to-string|preact-context-provider)[\\/]/;

if (cacheGroups.framework) {
cacheGroups.preact = Object.assign({}, cacheGroups.framework, {
test: preactModules
});
cacheGroups.commons.name = 'framework';
} else {
cacheGroups.preact = {
name: 'commons',
chunks: 'all',
test: preactModules
};
}
}

// Install webpack aliases:
const aliases = config.resolve.alias || (config.resolve.alias = {});
aliases.react = aliases['react-dom'] = 'preact/compat';
aliases.preact = path.resolve(__dirname, 'node_modules', 'preact');

// inject Preact DevTools
if (dev && !isServer) {
const entry = config.entry;
config.entry = () =>
entry().then(entries => {
entries['main.js'] = ['preact/debug'].concat(
entries['main.js'] || []
);
return entries;
});
}
aliases['preact/hooks'] = 'preact/compat'

return config;
}
Expand Down
6 changes: 3 additions & 3 deletions test/fixture/next-webpack5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
},
"dependencies": {
"goober": "latest",
"next": "^10.2.2",
"next": "^12.0.0",
"preact": "^10.5.7",
"preact-render-to-string": "^5.1.12",
"react": "github:preact-compat/react#1.0.0",
"react-dom": "github:preact-compat/react-dom#1.0.0",
"react": "npm:@preact/compat",
"react-dom": "npm:@preact/compat",
"react-ssr-prepass": "npm:preact-ssr-prepass@^1.0.1",
"webpack": "^5.0.0"
}
Expand Down
4 changes: 2 additions & 2 deletions test/fixture/next-webpack5/src/app.jsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { createElement } from 'react'
import { useCounter } from './useCounter'
import { h } from 'preact'
import { Greeting } from './greeting.jsx';
import { StoreProvider } from './context.jsx';
import { Products } from './products.jsx';
import { Effect } from './effect.jsx';
import { Style } from './styles';
import { setup } from 'goober';

setup(h);
setup(createElement);

function Test() {
const [count, increment] = useCounter();
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/next-webpack5/src/context.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { h, createContext } from 'preact';
import { useState } from 'preact/hooks';
import { createContext, useState } from 'react';

export const StoreContext = createContext();

Expand Down
3 changes: 1 addition & 2 deletions test/fixture/next-webpack5/src/effect.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { h } from 'preact';
import { useEffect, useState } from 'preact/hooks';
import { useEffect, useState } from 'react';

export const Effect = () => {
const [state, setState] = useState('');
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/next-webpack5/src/greeting.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { h, Component } from 'preact'
import { Component } from 'react'

export class Greeting extends Component {
constructor(props) {
Expand Down
3 changes: 1 addition & 2 deletions test/fixture/next-webpack5/src/products.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { h } from 'preact';
import { useContext } from 'preact/hooks';
import { useContext } from 'react';
import { StoreContext } from './context.jsx';

const products = ['apple', 'peach']
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/next-webpack5/src/useCounter.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState } from 'preact/hooks';
import { useState } from 'react';

export const useCounter = () => {
const [state, setState] = useState(0);
Expand Down

0 comments on commit 3ace276

Please sign in to comment.