This repository has been archived by the owner on Sep 11, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(build): upgrade to webpack 2
- Loading branch information
David Zukowski
committed
May 17, 2017
1 parent
1a4a71b
commit c58c0c3
Showing
48 changed files
with
2,884 additions
and
3,092 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
blueprints/**/files/** | ||
coverage/** | ||
node_modules/** | ||
dist/** | ||
|
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,9 +1,7 @@ | ||
.DS_STORE | ||
*.log | ||
|
||
node_modules | ||
|
||
dist | ||
coverage | ||
|
||
.idea/ | ||
.yarn-cache |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const argv = require('yargs').argv | ||
const webpackConfig = require('./webpack.config') | ||
|
||
const TEST_BUNDLER = './tests/test-bundler.js' | ||
|
||
const karmaConfig = { | ||
basePath: '../', | ||
browsers: ['PhantomJS'], | ||
singleRun: !argv.watch, | ||
coverageReporter: { | ||
reporters: [ | ||
{ type: 'text-summary' }, | ||
], | ||
}, | ||
files: [{ | ||
pattern : TEST_BUNDLER, | ||
watched : false, | ||
served : true, | ||
included : true | ||
}], | ||
frameworks: ['mocha'], | ||
reporters: ['mocha'], | ||
preprocessors: { | ||
[TEST_BUNDLER]: ['webpack'], | ||
}, | ||
logLevel: 'WARN', | ||
browserConsoleLogOptions: { | ||
terminal: true, | ||
format: '%b %T: %m', | ||
level: '', | ||
}, | ||
webpack: { | ||
entry: TEST_BUNDLER, | ||
devtool: 'cheap-module-source-map', | ||
module: webpackConfig.module, | ||
plugins: webpackConfig.plugins, | ||
resolve: webpackConfig.resolve, | ||
externals: { | ||
'react/addons': 'react', | ||
'react/lib/ExecutionEnvironment': 'react', | ||
'react/lib/ReactContext': 'react', | ||
}, | ||
}, | ||
webpackMiddleware: { | ||
stats: 'errors-only', | ||
noInfo: true, | ||
}, | ||
} | ||
|
||
module.exports = (cfg) => cfg.set(karmaConfig) |
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
const chalk = require('chalk') | ||
const figures = require('figures') | ||
|
||
exports.log = (...messages) => console.log(...messages) | ||
exports.error = (...messages) => console.error(chalk.red(figures.cross, ...messages)) | ||
exports.info = (...messages) => console.info(chalk.cyan(figures.info, ...messages)) | ||
exports.success = (...messages) => console.log(chalk.green(figures.tick, ...messages)) | ||
exports.warn = (...messages) => console.warn(chalk.yellow(figures.warning, ...messages)) |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const fs = require('fs-extra') | ||
const path = require('path') | ||
const chalk = require('chalk') | ||
const webpack = require('webpack') | ||
const logger = require('../lib/logger') | ||
const webpackConfig = require('../webpack.config') | ||
const project = require('../../project.config') | ||
|
||
const runWebpackCompiler = (webpackConfig) => | ||
new Promise((resolve, reject) => { | ||
webpack(webpackConfig).run((err, stats) => { | ||
if (err) { | ||
logger.error('Webpack compiler encountered a fatal error.', err) | ||
return reject(err) | ||
} | ||
|
||
const jsonStats = stats.toJson() | ||
if (jsonStats.errors.length > 0) { | ||
logger.error('Webpack compiler encountered errors.') | ||
logger.log(jsonStats.errors.join('\n')) | ||
return reject(new Error('Webpack compiler encountered errors')) | ||
} else if (jsonStats.warnings.length > 0) { | ||
logger.warn('Webpack compiler encountered warnings.') | ||
logger.log(jsonStats.warnings.join('\n')) | ||
} | ||
resolve(stats) | ||
}) | ||
}) | ||
|
||
const compile = () => Promise.resolve() | ||
.then(() => logger.info('Starting compiler...')) | ||
.then(() => logger.info('Target application environment: ' + chalk.bold(project.env))) | ||
.then(() => runWebpackCompiler(webpackConfig)) | ||
.then((stats) => { | ||
logger.info(`Copying static assets from ./public to ./${project.outDir}.`) | ||
fs.copySync( | ||
path.resolve(project.basePath, 'public'), | ||
path.resolve(project.basePath, project.outDir) | ||
) | ||
return stats | ||
}) | ||
.then((stats) => { | ||
if (project.verbose) { | ||
logger.log(stats.toString({ | ||
colors: true, | ||
chunks: false, | ||
})) | ||
} | ||
logger.success(`Compiler finished successfully! See ./${project.outDir}.`) | ||
}) | ||
.catch((err) => logger.error('Compiler encountered errors.', err)) | ||
|
||
compile() |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
const logger = require('../lib/logger') | ||
|
||
logger.info('Starting server...') | ||
require('../../server/main').listen(3000, () => { | ||
logger.success('Server is running at http://localhost:3000') | ||
}) |
Oops, something went wrong.