Skip to content

Commit

Permalink
Fix: Async component loader wrong path for 'async!...' imports (#50)
Browse files Browse the repository at this point in the history
* fix: wrong build path for 'async!' imports. Fixes #47

* fix: Incorrect async-component-loader refactor

* chore: Configure eslint & fix linting errors
  • Loading branch information
rkostrzewski authored and developit committed May 25, 2017
1 parent c079ba6 commit 35fd84a
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 8 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"build": "babel src -d lib -D",
"prepublish": "npm run -s build",
"dev": "babel-node src",
"lint": "eslint 'src/**/*.js'",
"test:build": "babel-node src build --cwd examples/root",
"test:serve": "npm run -s test:build && babel-node src serve --port 3000 --cwd examples/root",
"test:serve:config": "npm run -s test:build && babel-node src serve --server config --cwd examples/root",
Expand Down Expand Up @@ -51,6 +52,8 @@
"rules": {
"no-console": 1,
"no-empty": 0,
"semi": 2,
"keyword-spacing": 2,
"react/no-string-refs": 2,
"react/no-find-dom-node": 2,
"react/no-is-mounted": 2,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export default asyncCommand({
\u001b[32mnpm run serve\u001b[39m
`.trim().replace(/^\t+/gm, '') + '\n';
}
})
});


const npm = (cwd, args) => spawn('npm', args, { cwd, stdio: 'ignore' });
2 changes: 1 addition & 1 deletion src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function createHeadersFromPushManifest(pushManifest) {
`<${url}>; rel=preload; as=${type}`
).join(', ')
}]
})
});
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/commands/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ export default asyncCommand({
let stats = await runWebpack(true, config, showStats);
showStats(stats);
}
})
});
2 changes: 1 addition & 1 deletion src/lib/async-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ export default function asyncCommand(options) {
let r = options.handler(argv, done);
if (r && r.then) r.then(result => done(null, result), done);
}
}
};
}
9 changes: 8 additions & 1 deletion src/lib/async-component-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ module.exports.pitch = function(remainingRequest) {
this.cacheable && this.cacheable();
var query = loaderUtils.getOptions(this) || {};
var routeName = typeof query.name === 'function' ? query.name(this.resourcePath) : null;
var name = routeName !== null ? routeName : ('name' in query ? query.name : (query.formatName || String)(this.resourcePath));
var name;
if (routeName !== null) {
name = routeName;
} else if ('name' in query) {
name = query.name;
} else if ('formatName' in query) {
name = query.formatName(this.resourcePath);
}

return `
import async from ${JSON.stringify(path.resolve(__dirname, '../components/async'))};
Expand Down
2 changes: 1 addition & 1 deletion src/lib/babel-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ export default (env, options={}) => ({
import: 'h'
}]
]
})
});
1 change: 1 addition & 0 deletions src/lib/prerender.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default function prerender(config, params) {
app = m && m.default || m;

if (typeof app!=='function') {
// eslint-disable-next-line no-console
console.warn('Entry does not export a Component function/class, aborting prerendering.');
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/push-manifest.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ module.exports = class PushManifestPlugin {
callback();
});
}
}
};
2 changes: 1 addition & 1 deletion src/lib/run-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default (watch=false, config, onprogress) => new Promise( (resolve, rejec
// Timeout for plugins that work on `after-emit` event of webpack
setTimeout(()=>{
resolve(stats);
},20)
},20);
}
};

Expand Down

0 comments on commit 35fd84a

Please sign in to comment.