Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/lib/entry.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,5 @@ if (typeof app==='function') {

if (module.hot) module.hot.accept('preact-cli-entrypoint', init);

if (typeof fetch==='function') {
init();
}
else {
require.ensure(['preact-cli-polyfills'], () => {
require('preact-cli-polyfills');
init();
}, 'polyfills');
}
init();
}
10 changes: 7 additions & 3 deletions src/lib/webpack-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,14 @@ export default env => {

return createConfig.vanilla([
setContext(src('.')),
entryPoint(resolve(__dirname, './entry')),
entryPoint({
'bundle': resolve(__dirname, './entry'),
'polyfills': resolve(__dirname, './polyfills'),
}),
setOutput({
path: resolve(cwd, env.dest || 'build'),
publicPath: '/',
filename: 'bundle.js',
filename: '[name].js',
chunkFilename: '[name].chunk.[chunkhash:5].js'
}),

Expand All @@ -75,7 +78,6 @@ export default env => {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.less', '.scss', '.sass', '.css'],
alias: {
'preact-cli-entrypoint': src('index.js'),
'preact-cli-polyfills': resolve(__dirname, 'polyfills.js'),
style: src('style'),
preact$: isProd ? 'preact/dist/preact.min.js' : 'preact',
// preact-compat aliases for supporting React dependencies:
Expand Down Expand Up @@ -433,6 +435,7 @@ const production = config => addPlugins([
minify: true,
stripPrefix: config.cwd,
staticFileGlobsIgnorePatterns: [
/polyfills\.js$/,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you ignore this because all serviceWorker-compatible browsers don't need a fetch or Promise polyfill?

(^ I'm not certain that that's 100% true)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I understand serviceWorker implementation requires fetch implementation which in turn requires Promise implementation. Based on FetchEvent. I could be wrong tough.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, right. I believe that's the case too 👍 You upgraded my 90% certainty to 95% 😉

/\.map$/,
/push-manifest\.json$/
]
Expand All @@ -457,6 +460,7 @@ const htmlPlugin = config => addPlugins([
compile: true,
preload: config.preload===true,
title: config.title || config.manifest.name || config.manifest.short_name || (config.pkg.name || '').replace(/^@[a-z]\//, '') || 'Preact App',
excludeChunks: ['polyfills'],
config,
ssr(params) {
return config.prerender ? prerender(config, params) : '';
Expand Down
3 changes: 2 additions & 1 deletion src/resources/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<% } %>
<% for (var chunk of webpack.chunks) { %>
<% for (var file of chunk.files) { %>
<% if (htmlWebpackPlugin.options.preload && file.match(/\.(js|css)$/)) { %>
<% if (htmlWebpackPlugin.options.preload && file.match(/\.(js|css)$/) && file !== 'polyfills.js') { %>
<link rel="preload" href="<%= htmlWebpackPlugin.files.publicPath + file %>" as="<%= file.match(/\.css$/)?'style':'script' %>">
<% } else if (file.match(/manifest\.json$/)) { %>
<link rel="manifest" href="<%= htmlWebpackPlugin.files.publicPath + file %>">
Expand All @@ -24,5 +24,6 @@
<%= htmlWebpackPlugin.options.ssr({
url: '/'
}) %>
<script>"undefined"==typeof fetch&&document.write('<script src="<%= htmlWebpackPlugin.files.publicPath + "polyfills.js" %>"><\/script>')</script>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about (window.fetch===void 0) && ...?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds great! I'll change it to window.fetch==void 0&&document.write(...) (5 less characters & html webpack plugin doesn't minify inline script 😢 )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol okay. I was just going for perf since !== void 0 is faster than typeof === 'undefined'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're changing, maybe just go with window.fetch || document.write(..).

</body>
</html>