-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
292 additions
and
312 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,5 +1,13 @@ | ||
{ | ||
"presets": ["es2015", "stage-2"], | ||
"presets": [ | ||
["es2015", { "modules": false }], | ||
"stage-2" | ||
], | ||
"plugins": ["transform-runtime"], | ||
"comments": false | ||
"comments": false, | ||
"env": { | ||
"test": { | ||
"plugins": [ "istanbul" ] | ||
} | ||
} | ||
} |
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,44 +1,35 @@ | ||
// https://github.com/shelljs/shelljs | ||
require('./check-versions')() | ||
require('shelljs/global') | ||
env.NODE_ENV = 'production' | ||
|
||
var path = require('path') | ||
var config = require('../config') | ||
process.env.NODE_ENV = 'production' | ||
|
||
var ora = require('ora') | ||
var rm = require('rimraf') | ||
var path = require('path') | ||
var chalk = require('chalk') | ||
var webpack = require('webpack') | ||
var config = require('../config') | ||
var webpackConfig = require('./webpack.prod.conf') | ||
var _ = require('lodash') | ||
|
||
function prdBuild(customConfig, cb) { | ||
console.log( | ||
' Tip:\n' + | ||
' Built files are meant to be served over an HTTP server.\n' + | ||
' Opening index.html over file:// won\'t work.\n' | ||
) | ||
var spinner = ora('building for production...') | ||
spinner.start() | ||
|
||
var spinner = ora('building for production...') | ||
spinner.start() | ||
|
||
var assetsPath = path.join(config.build.assetsRoot, config.build.assetsSubDirectory) | ||
rm('-rf', assetsPath) | ||
mkdir('-p', assetsPath) | ||
cp('-R', 'static/*', assetsPath) | ||
|
||
webpack(customConfig, function (err, stats) { | ||
rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => { | ||
if (err) throw err | ||
webpack(webpackConfig, function (err, stats) { | ||
spinner.stop() | ||
if (err) throw err | ||
process.stdout.write(stats.toString({ | ||
colors: true, | ||
modules: false, | ||
children: false, | ||
chunks: false, | ||
chunkModules: false | ||
}) + '\n') | ||
_.isFunction(cb) && cb() | ||
}) | ||
} | ||
colors: true, | ||
modules: false, | ||
children: false, | ||
chunks: false, | ||
chunkModules: false | ||
}) + '\n\n') | ||
|
||
// prdBuild(webpackConfig) | ||
|
||
module.exports.prdBuild = prdBuild | ||
console.log(chalk.cyan(' Build complete.\n')) | ||
console.log(chalk.yellow( | ||
' Tip: built files are meant to be served over an HTTP server.\n' + | ||
' Opening index.html over file:// won\'t work.\n' | ||
)) | ||
}) | ||
}) |
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,79 +1,83 @@ | ||
require('./check-versions')() | ||
|
||
var config = require('../config') | ||
if (!process.env.NODE_ENV) process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) | ||
if (!process.env.NODE_ENV) { | ||
process.env.NODE_ENV = JSON.parse(config.dev.env.NODE_ENV) | ||
} | ||
|
||
var opn = require('opn') | ||
var path = require('path') | ||
var express = require('express') | ||
var webpack = require('webpack') | ||
var opn = require('opn') | ||
var proxyMiddleware = require('http-proxy-middleware') | ||
var webpackConfig = process.env.NODE_ENV === 'testing' | ||
? require('./webpack.prod.conf') | ||
: require('./webpack.dev.conf') | ||
|
||
// default port where dev server listens for incoming traffic | ||
var port = process.env.PORT || config.dev.port | ||
// automatically open browser, if not set will be false | ||
var autoOpenBrowser = !!config.dev.autoOpenBrowser | ||
// Define HTTP proxies to your custom API backend | ||
// https://github.com/chimurai/http-proxy-middleware | ||
var proxyTable = config.dev.proxyTable | ||
|
||
function devServe(customConfig) { | ||
var app = express() | ||
var compiler = webpack(customConfig) | ||
var app = express() | ||
var compiler = webpack(webpackConfig) | ||
|
||
var devMiddleware = require('webpack-dev-middleware')(compiler, { | ||
publicPath: customConfig.output.publicPath, | ||
stats: { | ||
colors: true, | ||
chunks: false | ||
} | ||
}) | ||
var devMiddleware = require('webpack-dev-middleware')(compiler, { | ||
publicPath: webpackConfig.output.publicPath, | ||
quiet: true | ||
}) | ||
|
||
var hotMiddleware = require('webpack-hot-middleware')(compiler) | ||
// force page reload when html-webpack-plugin template changes | ||
compiler.plugin('compilation', function (compilation) { | ||
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { | ||
hotMiddleware.publish({action: 'reload'}) | ||
cb() | ||
}) | ||
var hotMiddleware = require('webpack-hot-middleware')(compiler, { | ||
log: () => {} | ||
}) | ||
// force page reload when html-webpack-plugin template changes | ||
compiler.plugin('compilation', function (compilation) { | ||
compilation.plugin('html-webpack-plugin-after-emit', function (data, cb) { | ||
hotMiddleware.publish({ action: 'reload' }) | ||
cb() | ||
}) | ||
}) | ||
|
||
// proxy api requests | ||
Object.keys(proxyTable).forEach(function (context) { | ||
var options = proxyTable[context] | ||
if (typeof options === 'string') { | ||
options = {target: options} | ||
} | ||
app.use(proxyMiddleware(context, options)) | ||
}) | ||
// proxy api requests | ||
Object.keys(proxyTable).forEach(function (context) { | ||
var options = proxyTable[context] | ||
if (typeof options === 'string') { | ||
options = { target: options } | ||
} | ||
app.use(proxyMiddleware(options.filter || context, options)) | ||
}) | ||
|
||
// handle fallback for HTML5 history API | ||
app.use(require('connect-history-api-fallback')()) | ||
// handle fallback for HTML5 history API | ||
app.use(require('connect-history-api-fallback')()) | ||
|
||
// serve webpack bundle output | ||
app.use(devMiddleware) | ||
// serve webpack bundle output | ||
app.use(devMiddleware) | ||
|
||
// enable hot-reload and state-preserving | ||
// compilation error display | ||
app.use(hotMiddleware) | ||
// enable hot-reload and state-preserving | ||
// compilation error display | ||
app.use(hotMiddleware) | ||
|
||
// serve pure static assets | ||
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) | ||
app.use(staticPath, express.static('./static')) | ||
// serve pure static assets | ||
var staticPath = path.posix.join(config.dev.assetsPublicPath, config.dev.assetsSubDirectory) | ||
app.use(staticPath, express.static('./static')) | ||
|
||
return app.listen(port, function (err) { | ||
if (err) { | ||
console.log(err) | ||
return | ||
} | ||
var uri = 'http://localhost:' + port | ||
console.log('Listening at ' + uri + '\n') | ||
var uri = 'http://localhost:' + port | ||
|
||
// when env is testing, don't need open it | ||
if (process.env.NODE_ENV !== 'testing') { | ||
opn(uri) | ||
} | ||
devMiddleware.waitUntilValid(function () { | ||
console.log('> Listening at ' + uri + '\n') | ||
}) | ||
|
||
}) | ||
} | ||
module.exports = app.listen(port, function (err) { | ||
if (err) { | ||
console.log(err) | ||
return | ||
} | ||
|
||
module.exports.devServe = devServe | ||
// when env is testing, don't need open it | ||
if (autoOpenBrowser && process.env.NODE_ENV !== 'testing') { | ||
opn(uri) | ||
} | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
var utils = require('./utils') | ||
var config = require('../config') | ||
var isProduction = process.env.NODE_ENV === 'production' | ||
|
||
module.exports = { | ||
loaders: utils.cssLoaders({ | ||
sourceMap: isProduction | ||
? config.build.productionSourceMap | ||
: config.dev.cssSourceMap, | ||
extract: isProduction | ||
}), | ||
postcss: [ | ||
require('autoprefixer')({ | ||
browsers: ['last 2 versions'] | ||
}) | ||
] | ||
} |
Oops, something went wrong.