Skip to content

Commit 3994a23

Browse files
authored
chore: Misc cleaning (#1613)
1 parent 0cfee78 commit 3994a23

File tree

10 files changed

+70
-260
lines changed

10 files changed

+70
-260
lines changed

.changeset/unlucky-brooms-rule.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-cli': patch
3+
---
4+
5+
Removing old & non-functional config helper `setHtmlTemplate`

README.md

Lines changed: 35 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
- [preact watch](#preact-watch)
1414
- [preact list](#preact-list)
1515
- [preact info](#preact-info)
16-
- [Deploying](#deploying)
1716
- [Pre-rendering](#pre-rendering)
1817
- [Custom Configuration](#custom-configuration)
1918
- [Plugins](#plugins)
@@ -25,6 +24,8 @@
2524
- [Using CSS preprocessors](#using-css-preprocessors)
2625
- [SASS](#sass)
2726
- [LESS](#less)
27+
- [Using Environment Variables](#using-environment-variables)
28+
- [Route-Based Code Splitting](#route-based-code-splitting)
2829

2930
### Features
3031

@@ -44,7 +45,7 @@
4445

4546
### Requirements
4647

47-
> **Important**: [Node.js](https://nodejs.org/en/) > V8.x and npm 5.2+ is a minimum requirement.
48+
> **Important**: [Node.js](https://nodejs.org/en/) >= v12 is required.
4849
4950
### Usage
5051

@@ -148,7 +149,7 @@ $ preact watch
148149
--prerender Pre-render static content on first run
149150
--prerenderUrls Path to pre-rendered routes config (default prerender-urls.json)
150151
--template Path to custom HTML template
151-
--refresh Will use [`Preact-refresh`](https://github.com/JoviDeCroock/preact-refresh) to do hot-reloading
152+
--refresh Enables experimental preact-refresh functionality
152153
-c, --config Path to custom CLI config (default preact.config.js)
153154
-H, --host Set server hostname (default 0.0.0.0)
154155
-p, --port Set server port (default 8080)
@@ -172,18 +173,6 @@ $ preact list
172173

173174
Prints debugging information concerning the local environment.
174175

175-
### Deploying
176-
177-
```sh
178-
# create a production build:
179-
npm run build
180-
181-
# generate configuration in Firebase Hosting format:
182-
npm run serve -- --server config
183-
184-
# Copy your static files to a server!
185-
```
186-
187176
### Pre-rendering
188177

189178
Preact CLI in order to follow [PRPL] pattern renders initial route (`/`) into generated static `index.html` - this ensures that users get to see your page before any JavaScript is run, and thus providing users with slow devices or poor connection your website's content much faster.
@@ -308,7 +297,7 @@ module.exports = [
308297

309298
#### Template
310299

311-
A template is used to render your page by [EJS](https://ejs.co/).
300+
A template is used to render your page by [EJS](https://ejs.co/).
312301
You can uses the data of `prerenderUrls` which does not have `title`, using `htmlWebpackPlugin.options.CLI_DATA.preRenderData` in EJS.
313302

314303
The default one is visible [here](packages/cli/lib/resources/template.html) and it's going to be enough for the majority of cases.
@@ -352,36 +341,6 @@ export default {
352341

353342
If you'd like to use these variables in your application, you can use the [DefinePlugin] config from our recipes wiki.
354343

355-
[promise]: https://npm.im/promise-polyfill
356-
[fetch]: https://github.com/developit/unfetch
357-
[preact]: https://github.com/preactjs/preact
358-
[webpackconfighelpers]: docs/webpack-helpers.md
359-
[`.babelrc`]: https://babeljs.io/docs/usage/babelrc
360-
[simple]: https://github.com/preactjs-templates/simple
361-
[`"browserslist"`]: https://github.com/ai/browserslist
362-
[```.babelrc```]: https://babeljs.io/docs/usage/babelrc
363-
[default]: https://github.com/preactjs-templates/default
364-
[workbox]: https://developers.google.com/web/tools/workbox
365-
[preact-router]: https://github.com/preactjs/preact-router
366-
[material]: https://github.com/preactjs-templates/material
367-
[netlify]: https://github.com/preactjs-templates/netlify
368-
[typescript]: https://github.com/preactjs-templates/typescript
369-
[widget]: https://github.com/preactjs-templates/widget
370-
[plugins wiki]: https://github.com/preactjs/preact-cli/wiki/Plugins
371-
[preactjs-templates organization]: https://github.com/preactjs-templates
372-
[preactjs-templates/default]: https://github.com/preactjs-templates/default
373-
[recipes wiki]: https://github.com/preactjs/preact-cli/wiki/Config-Recipes
374-
[prpl]: https://developers.google.com/web/fundamentals/performance/prpl-pattern
375-
[`babel-preset-env`]: https://github.com/babel/babel-preset-env#targetsbrowsers
376-
[proof]: https://googlechrome.github.io/lighthouse/viewer/?gist=142af6838482417af741d966e7804346
377-
[preact cli preset]: https://github.com/preactjs/preact-cli/blob/master/packages/cli/lib/lib/babel-config.js
378-
[service workers]: https://developers.google.com/web/fundamentals/getting-started/primers/service-workers
379-
[customize babel]: https://github.com/preactjs/preact-cli/wiki/Config-Recipes#customising-babel-options-using-loader-helpers
380-
[`async!`]: https://github.com/preactjs/preact-cli/blob/1.4.1/examples/full/src/components/app.js#L7
381-
[sass]: https://sass-lang.com
382-
[less]: http://lesscss.org
383-
[defineplugin]: https://github.com/preactjs/preact-cli/wiki/Config-Recipes#use-environment-variables-in-your-application
384-
385344
### Route-Based Code Splitting
386345

387346
"Route" components are automatically code-splitted at build time to create smaller bundles and avoid loading more code than is needed by each page. This works by intercepting imports for route components with an [async loader](https://github.com/preactjs/preact-cli/tree/master/packages/async-loader), which returns a lightweight wrapper component that handles code splitting seamlessly.
@@ -411,7 +370,7 @@ Automatic code splitting is applied to all JavaScript and TypeScript files in th
411370
</td></tr>
412371
</tbody></table>
413372

414-
> **Note**:
373+
> **Note**:
415374
> Automatic code splitting **only** supports default exports, not named exports:
416375
>
417376
> ```diff
@@ -420,3 +379,32 @@ Automatic code splitting is applied to all JavaScript and TypeScript files in th
420379
> ```
421380
>
422381
> This is an intentional limitation that ensures effective code splitting. For components that need named exports, place them in a directory that doesn't trigger automatic code splitting. You can then manually code-split the default export by re-exporting it from `routes/` or importing it with the `"async!"` prefix.
382+
383+
[promise]: https://npm.im/promise-polyfill
384+
[fetch]: https://github.com/developit/unfetch
385+
[preact]: https://github.com/preactjs/preact
386+
[webpackconfighelpers]: docs/webpack-helpers.md
387+
[`.babelrc`]: https://babeljs.io/docs/usage/babelrc
388+
[simple]: https://github.com/preactjs-templates/simple
389+
[`"browserslist"`]: https://github.com/ai/browserslist
390+
[```.babelrc```]: https://babeljs.io/docs/usage/babelrc
391+
[default]: https://github.com/preactjs-templates/default
392+
[workbox]: https://developers.google.com/web/tools/workbox
393+
[preact-router]: https://github.com/preactjs/preact-router
394+
[netlify]: https://github.com/preactjs-templates/netlify
395+
[typescript]: https://github.com/preactjs-templates/typescript
396+
[widget]: https://github.com/preactjs-templates/widget
397+
[plugins wiki]: https://github.com/preactjs/preact-cli/wiki/Plugins
398+
[preactjs-templates organization]: https://github.com/preactjs-templates
399+
[preactjs-templates/default]: https://github.com/preactjs-templates/default
400+
[recipes wiki]: https://github.com/preactjs/preact-cli/wiki/Config-Recipes
401+
[prpl]: https://developers.google.com/web/fundamentals/performance/prpl-pattern
402+
[`babel-preset-env`]: https://github.com/babel/babel-preset-env#targetsbrowsers
403+
[proof]: https://googlechrome.github.io/lighthouse/viewer/?gist=142af6838482417af741d966e7804346
404+
[preact cli preset]: https://github.com/preactjs/preact-cli/blob/master/packages/cli/lib/lib/babel-config.js
405+
[service workers]: https://developers.google.com/web/fundamentals/getting-started/primers/service-workers
406+
[customize babel]: https://github.com/preactjs/preact-cli/wiki/Config-Recipes#customising-babel-options-using-loader-helpers
407+
[`async!`]: https://github.com/preactjs/preact-cli/blob/1.4.1/examples/full/src/components/app.js#L7
408+
[sass]: https://sass-lang.com
409+
[less]: http://lesscss.org
410+
[defineplugin]: https://github.com/preactjs/preact-cli/wiki/Config-Recipes#use-environment-variables-in-your-application

docs/webpack-helpers.md

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,6 @@ helpers.getPluginsByType(config, webpack.optimize.CommonsChunkPlugin);
118118

119119
Returns **[Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array)&lt;[PluginWrapper](#pluginwrapper)>**
120120

121-
### setHtmlTemplate
122-
123-
Sets template used by HtmlWebpackPlugin.
124-
125-
**Parameters**
126-
127-
- `config` **[object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** [webpack config](https://webpack.js.org/configuration/#options).
128-
- `template` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** template path. See [HtmlWebpackPlugin docs](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md).
129-
130121
## PluginWrapper
131122

132123
Wrapper around webpack's [plugin](https://webpack.js.org/configuration/plugins/#plugins).

packages/cli/lib/lib/webpack/transform-config.js

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { resolve } = require('path');
22
const webpack = require('webpack');
3-
const { statSync } = require('fs');
43
const { stat } = require('fs').promises;
54
const { error } = require('../../util');
65

@@ -274,34 +273,6 @@ class WebpackConfigHelpers {
274273
getPluginsByType(config, type) {
275274
return this.getPlugins(config).filter(w => w.plugin instanceof type);
276275
}
277-
278-
/**
279-
* Sets template used by HtmlWebpackPlugin.
280-
*
281-
* @param {object} config - [webpack config](https://webpack.js.org/configuration/#options).
282-
* @param {string} template - template path. See [HtmlWebpackPlugin docs](https://github.com/jantimon/html-webpack-plugin/blob/master/docs/template-option.md).
283-
*
284-
* @memberof WebpackConfigHelpers
285-
*/
286-
setHtmlTemplate(config, template) {
287-
let isPath;
288-
try {
289-
statSync(template);
290-
isPath = true;
291-
} catch (e) {}
292-
293-
let templatePath = isPath
294-
? `!!${require.resolve('ejs-loader')}?esModule=false!${resolve(
295-
this._cwd,
296-
template
297-
)}`
298-
: template;
299-
let { plugin: htmlWebpackPlugin } = this.getPluginsByName(
300-
config,
301-
'HtmlWebpackPlugin'
302-
)[0];
303-
htmlWebpackPlugin.options.template = templatePath;
304-
}
305276
}
306277

307278
/**

packages/cli/tests/build.snapshot.js

Lines changed: 0 additions & 90 deletions
This file was deleted.

packages/cli/tests/build.test.js

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ const images = require('./images/build');
99
const { promisify } = require('util');
1010
const glob = promisify(require('glob').glob);
1111

12-
// TODO
13-
// const ours = ['empty', 'full', 'simple', 'root'];
14-
const ours = ['default'];
15-
1612
const prerenderUrlFiles = [
1713
'prerender-urls.json',
1814
'prerender-urls.js',
@@ -50,26 +46,24 @@ function testMatch(src, tar) {
5046
}
5147

5248
describe('preact build', () => {
53-
ours.forEach(key => {
54-
it(`builds the '${key}' output`, async () => {
55-
let dir = await create(key);
49+
it(`builds the 'default' template`, async () => {
50+
let dir = await create('default');
5651

57-
await build(dir);
58-
dir = join(dir, 'build');
52+
await build(dir);
53+
dir = join(dir, 'build');
5954

60-
let output = await snapshot(dir);
61-
testMatch(output, images[key]);
62-
});
55+
let output = await snapshot(dir);
56+
testMatch(output, images.default);
57+
});
6358

64-
it(`builds the '${key}' output with esm`, async () => {
65-
let dir = await create(key);
59+
it(`builds the 'default' template with esm`, async () => {
60+
let dir = await create('default');
6661

67-
await build(dir, { esm: true });
68-
dir = join(dir, 'build');
62+
await build(dir, { esm: true });
63+
dir = join(dir, 'build');
6964

70-
let output = await snapshot(dir);
71-
testMatch(output, images[key + '-esm']);
72-
});
65+
let output = await snapshot(dir);
66+
testMatch(output, images['default-esm']);
7367
});
7468

7569
it('should use SASS styles', async () => {

packages/cli/tests/create.test.js

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,15 @@ const { create } = require('./lib/cli');
44
const { expand } = require('./lib/utils');
55
const snapshots = require('./images/create');
66

7-
// TODO: Move all `examples/` to `preactjs-templates`
8-
const ours = ['default'];
9-
107
describe('preact create', () => {
11-
ours.forEach(key => {
12-
it(`scaffolds the '${key}' official template`, async () => {
13-
let dir = await create(key);
14-
15-
let output = await expand(dir).then(arr => {
16-
return arr.map(x => relative(dir, x));
17-
});
8+
it(`scaffolds the 'default' official template`, async () => {
9+
let dir = await create('default');
1810

19-
expect(output.sort()).toEqual(snapshots[key]);
11+
let output = await expand(dir).then(arr => {
12+
return arr.map(x => relative(dir, x));
2013
});
14+
15+
expect(output.sort()).toEqual(snapshots.default);
2116
});
2217

2318
it(`should use template.html from the github repo`, async () => {
@@ -38,9 +33,10 @@ describe('preact create', () => {
3833
expect(template.includes('apple-touch-icon')).toEqual(true);
3934
});
4035

41-
// it('should fail given an invalid name', async () => {
42-
// const exit = jest.spyOn(process, 'exit');
43-
// await create('default', '*()@!#!$-invalid-name');
44-
// expect(exit).toHaveBeenCalledWith(1);
45-
// });
36+
it('should fail given an invalid name', async () => {
37+
const exit = jest.spyOn(process, 'exit').mockImplementation(() => {});
38+
await create('simple', '*()@!#!$-Invalid-Name');
39+
40+
expect(exit).toHaveBeenCalledWith(1);
41+
});
4642
});

packages/cli/tests/images/create.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const path = require('path');
22

33
exports.default = [
4-
// '.babelrc',
54
'.gitignore',
65
'package.json',
76
'README.md',

0 commit comments

Comments
 (0)