Last active
August 29, 2015 14:12
-
-
Save rogaldh/56032992415845bcc166 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var format = require('util').format; | |
var WebpackDevServer = require('webpack-dev-server'); | |
var webpack = require('webpack'); | |
var config = require('./webpack.config'); | |
var argv = require('yargs') | |
.boolean('h').alias('h', 'hot') | |
.argv; | |
var contentBase = { | |
target: format( | |
'http://%s:%d/', | |
process.env.SOURCE_IP || '192.168.59.103', | |
process.env.SOURCE_PORT || 8000 | |
) | |
}; | |
var port = process.env.PORT || 3000; | |
var host = process.env.IP || '0.0.0.0'; | |
var server = new WebpackDevServer(webpack(config), { | |
publicPath: config.output.publicPath, | |
hot: argv.h, | |
contentBase: contentBase | |
}); | |
server.listen(port, host, function(err, result) { | |
if (err) { | |
console.log(err); | |
} | |
}); |
This file contains hidden or 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
var webpack = require('webpack'); | |
var yargs = require('yargs') | |
var path = require('path') | |
var argv = yargs | |
.boolean('p').alias('p', 'optimize-minimize') | |
.boolean('h').alias('h', 'hot') | |
.argv; | |
module.exports = { | |
entry: (function() { | |
var entry = []; | |
if (argv.h) { | |
entry.push('webpack-dev-server/client?/'); | |
entry.push('webpack/hot/dev-server'); | |
} | |
entry.push(path.join(__dirname, 'lib', 'index.js')); | |
return entry; | |
})(), | |
output: { | |
path: path.join(__dirname, 'web', 'client'), | |
filename: 'client.js', | |
publicPath: '/client/' | |
}, | |
module: { | |
loaders: [ | |
{test: /\.js$/, exclude: /\/node_modules\//, loaders: [ | |
]}, | |
{test: /\.jsx$/, loaders: (function() { | |
var loaders = []; | |
if (argv.h) { | |
loaders.push('react-hot'); | |
} | |
loaders.push('jsx'); | |
return loaders; | |
})()}, | |
{test: /\.less$/, loaders: [ | |
'style', | |
'css', | |
'autoprefixer', | |
'less' | |
]}, | |
{test: /\.css$/, loaders: [ | |
'style', | |
'css', | |
'autoprefixer' | |
]}, | |
{test: /\.yml$/, loaders: [ | |
'yml' | |
]}, | |
{test: /\.json$/, loaders: [ | |
'json' | |
]}, | |
{test: /\.(png|jpg|gif)$/, loaders: (function() { | |
var loaders = []; | |
loaders.push('url?limit=50000'); | |
if (argv.p) { | |
loaders.push('image'); | |
} | |
return loaders; | |
})()}, | |
{test: /\.(ttf|eot|woff|svg)$/, loaders: [ | |
'file' | |
]} | |
] | |
}, | |
resolve: { | |
extensions: ['', '.js', '.jsx'] | |
}, | |
debug: !argv.p, | |
plugins: (function() { | |
var plugins = []; | |
plugins.push( | |
new webpack.DefinePlugin({ | |
'process.env.NODE_ENV': JSON.stringify(argv.p ? 'production' : 'development') | |
}) | |
); | |
if (argv.p) { | |
plugins.push(new webpack.optimize.UglifyJsPlugin()); | |
} | |
if (argv.h) { | |
plugins.push(new webpack.HotModuleReplacementPlugin()); | |
} | |
return plugins; | |
})() | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment