Skip to content

Commit 43316a3

Browse files
authored
Merge pull request #1383 from outoftime/upgrade-loop-breaker
Upgrade loop-breaker and load it asynchronously
2 parents 2aea002 + 56b4439 commit 43316a3

4 files changed

Lines changed: 36 additions & 24 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174
"jshint": "2.9.4",
175175
"keymirror": "^0.1.1",
176176
"lodash": "^4.15.0",
177-
"loop-breaker": "^0.1.0-alpha.7",
177+
"loop-breaker": "^0.1.0",
178178
"moment": "^2.14.1",
179179
"object-inspect": "^1.5.0",
180180
"offline-plugin": "^4.8.1",

src/util/compileProject.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import castArray from 'lodash/castArray';
22
import compact from 'lodash/compact';
33
import flatMap from 'lodash/flatMap';
44
import isEmpty from 'lodash/isEmpty';
5+
import trim from 'lodash/trim';
56
import uniq from 'lodash/uniq';
6-
import loopBreaker from 'loop-breaker';
77
import config from '../config';
88
import retryingFailedImports from '../util/retryingFailedImports';
99

@@ -149,9 +149,23 @@ async function addPreviewSupportScript(doc) {
149149
doc.head.appendChild(scriptTag);
150150
}
151151

152-
function addJavascript(doc, project, {breakLoops = false}) {
153-
let source = `\n${sourceDelimiter}\n${project.sources.javascript}`;
152+
async function addJavascript(
153+
doc,
154+
{sources: {javascript}},
155+
{breakLoops = false},
156+
) {
157+
if (trim(javascript).length === 0) {
158+
return;
159+
}
160+
161+
let source = `\n${sourceDelimiter}\n${javascript}`;
154162
if (breakLoops) {
163+
const loopBreaker = await retryingFailedImports(
164+
() => import(
165+
/* webpackChunkName: 'mainAsync' */
166+
'loop-breaker',
167+
),
168+
);
155169
source = loopBreaker(source);
156170
}
157171
const scriptTag = doc.createElement('script');
@@ -179,7 +193,7 @@ export default async function compileProject(
179193
if (isInlinePreview) {
180194
await addPreviewSupportScript(doc);
181195
}
182-
addJavascript(doc, project, {breakLoops: isInlinePreview});
196+
await addJavascript(doc, project, {breakLoops: isInlinePreview});
183197

184198
return {
185199
title: (doc.title || '').trim(),

webpack.config.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,11 +286,13 @@ module.exports = (env = 'development') => {
286286
test: /\.js$/,
287287
include: [
288288
matchModule('ansi-styles'),
289+
matchModule('ast-types'),
289290
matchModule('chalk'),
290291
matchModule('lodash-es'),
292+
matchModule('postcss-html'),
293+
matchModule('recast'),
291294
matchModule('redux'),
292295
matchModule('stylelint'),
293-
matchModule('postcss-html'),
294296
],
295297
use: {loader: 'babel-loader', options: babelrc},
296298
},

yarn.lock

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,7 @@ assign-symbols@^1.0.0:
529529
version "1.0.0"
530530
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"
531531

532-
ast-types@0.9.6:
533-
version "0.9.6"
534-
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.6.tgz#102c9e9e9005d3e7e3829bf0c4fa24ee862ee9b9"
535-
536-
ast-types@0.x.x:
532+
ast-types@0.11.2, ast-types@0.x.x:
537533
version "0.11.2"
538534
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.11.2.tgz#cc4e1d15a36b39979a1986fe1e91321cbfae7783"
539535

@@ -3764,15 +3760,15 @@ espree@^3.5.2:
37643760
acorn "^5.4.0"
37653761
acorn-jsx "^3.0.0"
37663762

3767-
esprima@3.x.x, esprima@^3.0.0, esprima@^3.1.3, esprima@~3.1.0:
3763+
esprima@3.x.x, esprima@^3.0.0, esprima@^3.1.3:
37683764
version "3.1.3"
37693765
resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633"
37703766

37713767
esprima@^2.6.0:
37723768
version "2.7.3"
37733769
resolved "https://registry.yarnpkg.com/esprima/-/esprima-2.7.3.tgz#96e3b70d5779f6ad49cd032673d1c312767ba581"
37743770

3775-
esprima@^4.0.0:
3771+
esprima@^4.0.0, esprima@~4.0.0:
37763772
version "4.0.0"
37773773
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"
37783774

@@ -6370,11 +6366,11 @@ longest@^1.0.1:
63706366
version "1.0.1"
63716367
resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097"
63726368

6373-
loop-breaker@^0.1.0-alpha.7:
6374-
version "0.1.0-alpha.8"
6375-
resolved "https://registry.yarnpkg.com/loop-breaker/-/loop-breaker-0.1.0-alpha.8.tgz#66b333754da4ec6c088fd74550f299f504aee815"
6369+
loop-breaker@^0.1.0:
6370+
version "0.1.0"
6371+
resolved "https://registry.yarnpkg.com/loop-breaker/-/loop-breaker-0.1.0.tgz#7706c40abe20cb498d1c30b0672a203b9bcc6547"
63766372
dependencies:
6377-
recast "^0.11.22"
6373+
recast "^0.14.4"
63786374

63796375
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
63806376
version "1.3.1"
@@ -8708,14 +8704,14 @@ readdirp@^2.0.0:
87088704
readable-stream "^2.0.2"
87098705
set-immediate-shim "^1.0.1"
87108706

8711-
recast@^0.11.22:
8712-
version "0.11.23"
8713-
resolved "https://registry.yarnpkg.com/recast/-/recast-0.11.23.tgz#451fd3004ab1e4df9b4e4b66376b2a21912462d3"
8707+
recast@^0.14.4:
8708+
version "0.14.4"
8709+
resolved "https://registry.yarnpkg.com/recast/-/recast-0.14.4.tgz#383dd606eac924c1157b0293b53191c34bd3c641"
87148710
dependencies:
8715-
ast-types "0.9.6"
8716-
esprima "~3.1.0"
8711+
ast-types "0.11.2"
8712+
esprima "~4.0.0"
87178713
private "~0.1.5"
8718-
source-map "~0.5.0"
8714+
source-map "~0.6.1"
87198715

87208716
rechoir@^0.6.2:
87218717
version "0.6.2"
@@ -9737,7 +9733,7 @@ source-map@0.5.0:
97379733
version "0.5.0"
97389734
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.0.tgz#0fe96503ac86a5adb5de63f4e412ae4872cdbe86"
97399735

9740-
source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.1, source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.0, source-map@~0.5.1, source-map@~0.5.3:
9736+
source-map@0.5.x, source-map@^0.5.0, source-map@^0.5.1, source-map@^0.5.3, source-map@^0.5.6, source-map@^0.5.7, source-map@~0.5.1, source-map@~0.5.3:
97419737
version "0.5.7"
97429738
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"
97439739

0 commit comments

Comments
 (0)