Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
"jshint": "2.9.4",
"keymirror": "^0.1.1",
"lodash": "^4.15.0",
"loop-breaker": "^0.1.0-alpha.7",
"loop-breaker": "^0.1.0",
"moment": "^2.14.1",
"object-inspect": "^1.5.0",
"offline-plugin": "^4.8.1",
Expand Down
22 changes: 18 additions & 4 deletions src/util/compileProject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import castArray from 'lodash/castArray';
import compact from 'lodash/compact';
import flatMap from 'lodash/flatMap';
import isEmpty from 'lodash/isEmpty';
import trim from 'lodash/trim';
import uniq from 'lodash/uniq';
import loopBreaker from 'loop-breaker';
import config from '../config';
import retryingFailedImports from '../util/retryingFailedImports';

Expand Down Expand Up @@ -149,9 +149,23 @@ async function addPreviewSupportScript(doc) {
doc.head.appendChild(scriptTag);
}

function addJavascript(doc, project, {breakLoops = false}) {
let source = `\n${sourceDelimiter}\n${project.sources.javascript}`;
async function addJavascript(
doc,
{sources: {javascript}},
{breakLoops = false},
) {
if (trim(javascript).length === 0) {
return;
}

let source = `\n${sourceDelimiter}\n${javascript}`;
if (breakLoops) {
const loopBreaker = await retryingFailedImports(
() => import(
/* webpackChunkName: 'mainAsync' */
'loop-breaker',
),
);
source = loopBreaker(source);
}
const scriptTag = doc.createElement('script');
Expand Down Expand Up @@ -179,7 +193,7 @@ export default async function compileProject(
if (isInlinePreview) {
await addPreviewSupportScript(doc);
}
addJavascript(doc, project, {breakLoops: isInlinePreview});
await addJavascript(doc, project, {breakLoops: isInlinePreview});

return {
title: (doc.title || '').trim(),
Expand Down
4 changes: 3 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,13 @@ module.exports = (env = 'development') => {
test: /\.js$/,
include: [
matchModule('ansi-styles'),
matchModule('ast-types'),
matchModule('chalk'),
matchModule('lodash-es'),
matchModule('postcss-html'),
matchModule('recast'),
matchModule('redux'),
matchModule('stylelint'),
matchModule('postcss-html'),
],
use: {loader: 'babel-loader', options: babelrc},
},
Expand Down
32 changes: 14 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -529,11 +529,7 @@ assign-symbols@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/assign-symbols/-/assign-symbols-1.0.0.tgz#59667f41fadd4f20ccbc2bb96b8d4f7f78ec0367"

ast-types@0.9.6:
version "0.9.6"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.6.tgz#102c9e9e9005d3e7e3829bf0c4fa24ee862ee9b9"

ast-types@0.x.x:
ast-types@0.11.2, ast-types@0.x.x:
version "0.11.2"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.11.2.tgz#cc4e1d15a36b39979a1986fe1e91321cbfae7783"

Expand Down Expand Up @@ -3764,15 +3760,15 @@ espree@^3.5.2:
acorn "^5.4.0"
acorn-jsx "^3.0.0"

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

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

esprima@^4.0.0:
esprima@^4.0.0, esprima@~4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804"

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

loop-breaker@^0.1.0-alpha.7:
version "0.1.0-alpha.8"
resolved "https://registry.yarnpkg.com/loop-breaker/-/loop-breaker-0.1.0-alpha.8.tgz#66b333754da4ec6c088fd74550f299f504aee815"
loop-breaker@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/loop-breaker/-/loop-breaker-0.1.0.tgz#7706c40abe20cb498d1c30b0672a203b9bcc6547"
dependencies:
recast "^0.11.22"
recast "^0.14.4"

loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.3.1:
version "1.3.1"
Expand Down Expand Up @@ -8708,14 +8704,14 @@ readdirp@^2.0.0:
readable-stream "^2.0.2"
set-immediate-shim "^1.0.1"

recast@^0.11.22:
version "0.11.23"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.11.23.tgz#451fd3004ab1e4df9b4e4b66376b2a21912462d3"
recast@^0.14.4:
version "0.14.4"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.14.4.tgz#383dd606eac924c1157b0293b53191c34bd3c641"
dependencies:
ast-types "0.9.6"
esprima "~3.1.0"
ast-types "0.11.2"
esprima "~4.0.0"
private "~0.1.5"
source-map "~0.5.0"
source-map "~0.6.1"

rechoir@^0.6.2:
version "0.6.2"
Expand Down Expand Up @@ -9737,7 +9733,7 @@ source-map@0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.0.tgz#0fe96503ac86a5adb5de63f4e412ae4872cdbe86"

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:
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:
version "0.5.7"
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc"

Expand Down