-
-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP - Use Pundle as the module bundler #268
Closed
Closed
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
1468346
:fire: Remove react stuff from manifest
643e7f5
:new: Add pundle and friends to manifest
4aba8c7
:new: Use the Pundle dev server
2b1e0c7
:arrow_up: Bump pundle versions
6c244e6
:art: Use fixed dependency versions
1f19c9b
:new: Use the standard ports for dev server
3f7636f
:art: Make start script the same code style as other files
be327e9
:arrow_up: Upgrade build.js to use pundle
57ba260
:fire: Remove outdated webpack configs
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,192 +1,46 @@ | ||
/** | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the BSD-style license found in the | ||
* LICENSE file in the root directory of this source tree. An additional grant | ||
* of patent rights can be found in the PATENTS file in the same directory. | ||
*/ | ||
|
||
process.env.NODE_ENV = 'development'; | ||
|
||
var path = require('path'); | ||
var chalk = require('chalk'); | ||
var webpack = require('webpack'); | ||
var WebpackDevServer = require('webpack-dev-server'); | ||
var execSync = require('child_process').execSync; | ||
var opn = require('opn'); | ||
var detect = require('detect-port'); | ||
var prompt = require('./utils/prompt'); | ||
var config = require('../config/webpack.config.dev'); | ||
|
||
// Tools like Cloud9 rely on this | ||
var DEFAULT_PORT = process.env.PORT || 3000; | ||
var compiler; | ||
|
||
// TODO: hide this behind a flag and eliminate dead code on eject. | ||
// This shouldn't be exposed to the user. | ||
var handleCompile; | ||
var isSmokeTest = process.argv.some(arg => arg.indexOf('--smoke-test') > -1); | ||
if (isSmokeTest) { | ||
handleCompile = function (err, stats) { | ||
if (err || stats.hasErrors() || stats.hasWarnings()) { | ||
process.exit(1); | ||
} else { | ||
process.exit(0); | ||
} | ||
}; | ||
} | ||
|
||
var friendlySyntaxErrorLabel = 'Syntax error:'; | ||
|
||
function isLikelyASyntaxError(message) { | ||
return message.indexOf(friendlySyntaxErrorLabel) !== -1; | ||
} | ||
|
||
// This is a little hacky. | ||
// It would be easier if webpack provided a rich error object. | ||
|
||
function formatMessage(message) { | ||
return message | ||
// Make some common errors shorter: | ||
.replace( | ||
// Babel syntax error | ||
'Module build failed: SyntaxError:', | ||
friendlySyntaxErrorLabel | ||
) | ||
.replace( | ||
// Webpack file not found error | ||
/Module not found: Error: Cannot resolve 'file' or 'directory'/, | ||
'Module not found:' | ||
) | ||
// Internal stacks are generally useless so we strip them | ||
.replace(/^\s*at\s.*:\d+:\d+[\s\)]*\n/gm, '') // at ... ...:x:y | ||
// Webpack loader names obscure CSS filenames | ||
.replace('./~/css-loader!./~/postcss-loader!', ''); | ||
} | ||
|
||
function clearConsole() { | ||
process.stdout.write('\x1bc'); | ||
} | ||
|
||
function setupCompiler(port) { | ||
compiler = webpack(config, handleCompile); | ||
|
||
compiler.plugin('invalid', function() { | ||
clearConsole(); | ||
console.log('Compiling...'); | ||
}); | ||
|
||
compiler.plugin('done', function(stats) { | ||
clearConsole(); | ||
var hasErrors = stats.hasErrors(); | ||
var hasWarnings = stats.hasWarnings(); | ||
if (!hasErrors && !hasWarnings) { | ||
console.log(chalk.green('Compiled successfully!')); | ||
console.log(); | ||
console.log('The app is running at http://localhost:' + port + '/'); | ||
console.log(); | ||
return; | ||
} | ||
|
||
var json = stats.toJson(); | ||
var formattedErrors = json.errors.map(message => | ||
'Error in ' + formatMessage(message) | ||
); | ||
var formattedWarnings = json.warnings.map(message => | ||
'Warning in ' + formatMessage(message) | ||
); | ||
|
||
if (hasErrors) { | ||
console.log(chalk.red('Failed to compile.')); | ||
console.log(); | ||
if (formattedErrors.some(isLikelyASyntaxError)) { | ||
// If there are any syntax errors, show just them. | ||
// This prevents a confusing ESLint parsing error | ||
// preceding a much more useful Babel syntax error. | ||
formattedErrors = formattedErrors.filter(isLikelyASyntaxError); | ||
} | ||
formattedErrors.forEach(message => { | ||
console.log(message); | ||
console.log(); | ||
}); | ||
// If errors exist, ignore warnings. | ||
return; | ||
} | ||
|
||
if (hasWarnings) { | ||
console.log(chalk.yellow('Compiled with warnings.')); | ||
console.log(); | ||
formattedWarnings.forEach(message => { | ||
console.log(message); | ||
console.log(); | ||
}); | ||
|
||
console.log('You may use special comments to disable some warnings.'); | ||
console.log('Use ' + chalk.yellow('// eslint-disable-next-line') + ' to ignore the next line.'); | ||
console.log('Use ' + chalk.yellow('/* eslint-disable */') + ' to ignore all warnings in a file.'); | ||
} | ||
}); | ||
} | ||
|
||
function openBrowser(port) { | ||
if (process.platform === 'darwin') { | ||
try { | ||
// Try our best to reuse existing tab | ||
// on OS X Google Chrome with AppleScript | ||
execSync('ps cax | grep "Google Chrome"'); | ||
execSync( | ||
'osascript ' + | ||
path.resolve(__dirname, './utils/chrome.applescript') + | ||
' http://localhost:' + port + '/' | ||
); | ||
return; | ||
} catch (err) { | ||
// Ignore errors. | ||
} | ||
} | ||
// Fallback to opn | ||
// (It will always open new tab) | ||
opn('http://localhost:' + port + '/'); | ||
} | ||
|
||
function runDevServer(port) { | ||
new WebpackDevServer(compiler, { | ||
historyApiFallback: true, | ||
hot: true, // Note: only CSS is currently hot reloaded | ||
publicPath: config.output.publicPath, | ||
quiet: true | ||
}).listen(port, (err, result) => { | ||
if (err) { | ||
return console.log(err); | ||
} | ||
|
||
clearConsole(); | ||
console.log(chalk.cyan('Starting the development server...')); | ||
console.log(); | ||
openBrowser(port); | ||
}); | ||
} | ||
|
||
function run(port) { | ||
setupCompiler(port); | ||
runDevServer(port); | ||
} | ||
|
||
detect(DEFAULT_PORT).then(port => { | ||
if (port === DEFAULT_PORT) { | ||
run(port); | ||
return; | ||
} | ||
|
||
clearConsole(); | ||
var question = | ||
chalk.yellow('Something is already running at port ' + DEFAULT_PORT + '.') + | ||
'\n\nWould you like to run the app at another port instead?'; | ||
|
||
prompt(question, true).then(shouldChangePort => { | ||
if (shouldChangePort) { | ||
run(port); | ||
} | ||
}); | ||
}); | ||
require('process-bootstrap')('react-app', 'REACT-APP') | ||
|
||
const Path = require('path') | ||
const debug = require('debug') | ||
const Server = require('pundle-dev') | ||
const debugInfo = debug('REACT-APP:Info') | ||
const debugError = debug('REACT-APP:Error') | ||
|
||
const port = 8056 | ||
|
||
const server = new Server({ | ||
pundle: { | ||
entry: ['index.js'], | ||
rootDirectory: Path.normalize(Path.join(__dirname, '../template/src')), | ||
pathType: 'filePath', | ||
moduleDirectories: ['node_modules'], | ||
}, | ||
server: { | ||
port, | ||
error(error) { | ||
debugError(error) | ||
}, | ||
ready() { | ||
debugInfo('Ready') | ||
}, | ||
generated() { | ||
debugInfo('Regenerated') | ||
}, | ||
hmr: true, | ||
sourceMap: true, | ||
sourceRoot: Path.normalize(Path.join(__dirname, '../template')), | ||
}, | ||
watcher: {}, | ||
generator: { | ||
sourceMap: true, | ||
wrapper: 'hmr', | ||
}, | ||
}) | ||
|
||
server.pundle.loadPlugins([ | ||
[require.resolve('babel-pundle'), { | ||
config: require('../config/babel.dev'), | ||
}], | ||
]).then(function() { | ||
return server.activate() | ||
}).catch((e) => console.log('error', e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this be
process.env.PORT || 3000
?