Last active
March 29, 2016 07:49
-
-
Save sang4lv/0309ce9a40bbc2722cb7 to your computer and use it in GitHub Desktop.
webpack
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 WebpackDevServer = require('webpack-dev-server'); | |
var webpack = require('webpack'); | |
var devConfig = require('../webpack.config.dev'); | |
var compiler = webpack(devConfig); | |
var IPAddress = require('./get-ip')(); | |
new WebpackDevServer(compiler, { | |
contentBase: './src', | |
publicPath: '/assets/', | |
stats: { | |
chunks: false | |
} | |
}).listen(3000, IPAddress, function() { | |
console.log('Webpack server is listening at http://%s:%s', IPAddress, 3000); | |
}); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<meta name="viewport" content="width=device-width, initial-scale=0.5, user-scalable=no"> | |
<title><%= htmlWebpackPlugin.options.title %></title> | |
<style> | |
body.dark { | |
background-color: #07021d; | |
} | |
body.light { | |
background-color: #ffffff; | |
} | |
</style> | |
</head> | |
<body class="dark"> | |
<div id="app"></div> | |
<span id="ip" style="display: none;"><%= htmlWebpackPlugin.options.ip %></span> | |
<script> | |
var _selfIP = document.getElementById('ip').textContent; | |
SimulateCommand('MOCK_INIT', location.hash.split('/').reduce(function(result, part) { | |
if (part !== '' && part !== '#') { | |
if (!result.appId) { | |
result.appId = part; | |
} else { | |
result.pageId = part; | |
} | |
} | |
return result; | |
}, {})); | |
</script> | |
</body> | |
</html> |
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 path = require('path'); | |
var webpack = require('webpack'); | |
var autoprefixer = require('autoprefixer'); | |
var HtmlWebpackPlugin = require('html-webpack-plugin'); | |
var IPAddress = require('./dev/get-ip')(); | |
var serverPort = '3000'; | |
module.exports = { | |
entry: [ | |
'babel-polyfill', | |
'./src/index', | |
'webpack-dev-server/client?http://' + IPAddress + ':' + serverPort, | |
'webpack/hot/only-dev-server' | |
], | |
output: { | |
path: __dirname + '/assets', | |
publicPath: '/assets/', | |
filename: 'platform.js' | |
}, | |
devtool: 'cheap-module-eval-source-map', | |
module: { | |
loaders: [ | |
{ | |
loader: 'babel-loader', | |
test: /\.jsx?$/, | |
exclude: /(node_modules)/, | |
query: { | |
presets: ['react', 'es2015'], | |
plugins: ['transform-object-assign'] | |
} | |
}, { | |
test: /\.svg$/, | |
loader: 'svg-inline' | |
}, { | |
test: /\.scss?$/, | |
loader: 'style!css!postcss!sass' | |
}, { | |
test: /\.(png|jpg|jpeg|gif)$/, | |
loader: 'file-loader', | |
query: { | |
limit: 10000 | |
} | |
} | |
] | |
}, | |
postcss: [ | |
autoprefixer({ | |
browsers: ['android 4.3', 'ios 8.4'] | |
}) | |
], | |
plugins: [ | |
new HtmlWebpackPlugin({ | |
ip: IPAddress, | |
title: 'Platform', | |
inject: 'head', | |
template: 'ejs!./src/index.ejs', | |
files: { | |
'js': ['http://' + IPAddress + ':3001/static/bridge.js', './assets/platform.js'] | |
} | |
}), | |
new webpack.HotModuleReplacementPlugin() | |
], | |
debug: true | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment