Skip to content

Commit 96b6d6b

Browse files
committed
Add prettier
1 parent e8e57a0 commit 96b6d6b

File tree

7 files changed

+313
-57
lines changed

7 files changed

+313
-57
lines changed

alias.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
const moduleAlias = require('module-alias');
1+
const moduleAlias = require("module-alias");
22

33
module.exports = () => {
4-
const renderToString = require('preact-render-to-string');
5-
if (!renderToString.renderToStaticMarkup) { renderToString.renderToStaticMarkup = renderToString; }
6-
moduleAlias.addAlias('react', 'preact/compat');
7-
moduleAlias.addAlias('react-dom', 'preact/compat');
8-
moduleAlias.addAlias('react-ssr-prepass', 'preact-ssr-prepass');
4+
const renderToString = require("preact-render-to-string");
5+
if (!renderToString.renderToStaticMarkup) {
6+
renderToString.renderToStaticMarkup = renderToString;
7+
}
8+
moduleAlias.addAlias("react", "preact/compat");
9+
moduleAlias.addAlias("react-dom", "preact/compat");
10+
moduleAlias.addAlias("react-ssr-prepass", "preact-ssr-prepass");
911
};

demo/lazy.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import React from 'react';
1+
import React from "react";
22

33
export default function LazyComp() {
4-
return <div>Hi Lazy!</div>;
4+
return <div>Hi Lazy!</div>;
55
}

demo/next.config.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// next.config.js
2-
const withPreact = require('../');
2+
const withPreact = require("../");
33

44
module.exports = withPreact({
5-
6-
/* config options here */
5+
/* config options here */
76
});

demo/pages/index.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import React from 'react';
2-
import dynamic from 'next/dynamic';
1+
import React from "react";
2+
import dynamic from "next/dynamic";
33

4-
const L = dynamic(() => import('../lazy'));
4+
const L = dynamic(() => import("../lazy"));
55

66
export default function App() {
7-
return (
8-
<div>
9-
Hello world!
10-
<L />
11-
</div>
12-
);
7+
return (
8+
<div>
9+
Hello world!
10+
<L />
11+
</div>
12+
);
1313
}

package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,22 @@
1919
"bin": {
2020
"next-preact": "./cli.js"
2121
},
22+
"husky": {
23+
"hooks": {
24+
"pre-commit": "pretty-quick --staged *.js demo/*.js demo/pages/*.js"
25+
}
26+
},
2227
"devDependencies": {
2328
"eslint": "^6.0.1",
2429
"eslint-config-developit": "^1.1.1",
2530
"eslint-plugin-compat": "2.7.0",
2631
"eslint-plugin-mocha": "4.12.1",
32+
"husky": "^4.2.5",
2733
"karma": "^4.1.0",
2834
"next": "^9.0.0",
29-
"preact": "^10.0.0-beta.3 || ^10.0.0-rc.0 || ^10"
35+
"preact": "^10.0.0-beta.3 || ^10.0.0-rc.0 || ^10",
36+
"prettier": "^2.0.5",
37+
"pretty-quick": "^2.0.1"
3038
},
3139
"dependencies": {
3240
"module-alias": "^2.0.0",

plugin.js

Lines changed: 39 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,44 @@
1-
module.exports = (nextConfig = {}) => Object.assign({}, nextConfig, {
2-
webpack(config, options) {
3-
if (!options.defaultLoaders) {
4-
throw new Error(
5-
'This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade'
6-
);
7-
}
1+
module.exports = (nextConfig = {}) =>
2+
Object.assign({}, nextConfig, {
3+
webpack(config, options) {
4+
if (!options.defaultLoaders) {
5+
throw new Error(
6+
"This plugin is not compatible with Next.js versions below 5.0.0 https://err.sh/next-plugins/upgrade"
7+
);
8+
}
89

9-
if (options.isServer) {
10-
config.externals = ['react', 'react-dom', 'react-ssr-prepass', ...config.externals];
11-
}
10+
if (options.isServer) {
11+
config.externals = [
12+
"react",
13+
"react-dom",
14+
"react-ssr-prepass",
15+
...config.externals,
16+
];
17+
}
1218

13-
config.resolve.alias = Object.assign({}, config.resolve.alias, {
14-
react: 'preact/compat',
15-
'react-dom': 'preact/compat'
16-
});
19+
config.resolve.alias = Object.assign({}, config.resolve.alias, {
20+
react: "preact/compat",
21+
"react-dom": "preact/compat",
22+
});
1723

18-
if (typeof nextConfig.webpack === 'function') {
19-
config = nextConfig.webpack(config, options);
20-
}
24+
if (typeof nextConfig.webpack === "function") {
25+
config = nextConfig.webpack(config, options);
26+
}
2127

22-
if (
23-
config.optimization &&
24-
config.optimization.splitChunks &&
25-
config.optimization.splitChunks.cacheGroups &&
26-
config.optimization.splitChunks.cacheGroups.framework
27-
) {
28-
config.optimization.splitChunks.cacheGroups.framework.test = new RegExp(
29-
'(' +
30-
config.optimization.splitChunks.cacheGroups.framework.test.source +
31-
')|((?<!node_modules.*)[\\/]node_modules[\\/](preact)[\\/])',
32-
config.optimization.splitChunks.cacheGroups.framework.test.flags
33-
);
34-
}
28+
if (
29+
config.optimization &&
30+
config.optimization.splitChunks &&
31+
config.optimization.splitChunks.cacheGroups &&
32+
config.optimization.splitChunks.cacheGroups.framework
33+
) {
34+
config.optimization.splitChunks.cacheGroups.framework.test = new RegExp(
35+
"(" +
36+
config.optimization.splitChunks.cacheGroups.framework.test.source +
37+
")|((?<!node_modules.*)[\\/]node_modules[\\/](preact)[\\/])",
38+
config.optimization.splitChunks.cacheGroups.framework.test.flags
39+
);
40+
}
3541

36-
return config;
37-
}
38-
});
42+
return config;
43+
},
44+
});

0 commit comments

Comments
 (0)