-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/detachWebpack'
- Loading branch information
Showing
8 changed files
with
223 additions
and
196 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
### v0.9.0 (2015-09-24) | ||
|
||
Let's kick the dust off and start with the good stuff! | ||
|
||
The file `vtex-webpack` is now **gone** (we won't miss you, so k bye). Now we have a new one, shiny and pretty called `webpack` (yep), it lives on the `lib` folder. | ||
|
||
The logic behind the `-w` and `-s` options is now there, and the entrypoint for them is now on `vtex-watch`, which makes much more sense since they are options of **watch**. | ||
|
||
Last but not least, the VTEX Toolbelt server now uses the new [react-transform](https://github.com/gaearon/react-transform)! | ||
|
||
Instead of using `webpack-dev-server `, we're using an `express` server with `webpack-hot-middleware` and `webpack-dev-middleware`. Note that `webpack-dev-middleware` doesn't write anything on disk and handles everything in memory, so don't freak out if you see your `assets` folder sitting there all alone. | ||
|
||
This assumes some pre-configuration on the project to work properly (see [Hot Module Replacement](https://github.com/vtex/toolbelt#hot-module-replacement) section on README). Besides, it's a world of new possibilities and probably makes it easier to make the dreamy multiple app hot reload that we all want! | ||
|
||
On this release two main issues are fulfilled (actually, one is partially done): | ||
|
||
- [`#44`](https://github.com/vtex/toolbelt/issues/44) (this is the partially one) | ||
- [`#35`](https://github.com/vtex/toolbelt/issues/35) |
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,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 VTEX | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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 |
---|---|---|
@@ -0,0 +1,100 @@ | ||
webpack = require 'webpack' | ||
express = require 'express' | ||
httpProxy = require 'http-proxy' | ||
path = require 'path' | ||
net = require 'net' | ||
chalk = require 'chalk' | ||
|
||
class WebpackOption | ||
constructor: -> | ||
try | ||
@config = require process.cwd() + '/webpack.config.js' | ||
catch err | ||
if err.code is 'MODULE_NOT_FOUND' | ||
pkgName = err.toString().match(/'(.*)'/)[1] | ||
|
||
if pkgName.indexOf('webpack.config.js') isnt -1 | ||
console.log 'webpack.config.js not found'.bold.yellow | ||
else | ||
console.log err.toString().bold.red | ||
console.log "Did you installed #{pkgName.yellow}?" | ||
|
||
process.exit 1 | ||
|
||
@compiler = webpack @config | ||
@DELAY_TIME = 2000 | ||
|
||
startDevServer: => | ||
runDevServer = => | ||
setTimeout => | ||
proxy = new httpProxy.createProxyServer() | ||
app = express() | ||
app.use require('webpack-dev-middleware')(@compiler, | ||
noInfo: true | ||
publicPath: @config.output.publicPath | ||
) | ||
app.use require('webpack-hot-middleware')(@compiler) | ||
|
||
if @config.proxy | ||
if !Array.isArray @config.proxy | ||
@config.proxy = Object.keys(@config.proxy).map (path) => | ||
if typeof @config.proxy[path] is 'string' | ||
proxyOptions = path: path, target: @config.proxy[path] | ||
else | ||
proxyOptions = @config.proxy[path] | ||
proxyOptions.path = path | ||
|
||
proxyOptions | ||
|
||
@config.proxy.forEach (proxyOptions) -> | ||
app.all proxyOptions.path, (req, res) -> | ||
if typeof proxyOptions.rewrite is 'function' | ||
proxyOptions.rewrite req, proxyOptions | ||
|
||
if proxyOptions.host | ||
req.headers.host = proxyOptions.host | ||
|
||
proxy.web req, res, proxyOptions, (err) => | ||
msg = "cannot proxy to #{proxyOptions.target} (#{err.message})" | ||
res.statusCode = 502 | ||
res.end() | ||
|
||
if proxyOptions.configure | ||
proxyOptions.configure proxy | ||
|
||
app.listen 3000, 'localhost', (err) => | ||
if err | ||
console.log err | ||
return | ||
console.log 'Listening at http://localhost:3000' | ||
, @DELAY_TIME | ||
|
||
testPort = net.createServer() | ||
.once 'error', (err) -> | ||
if err.code is 'EADDRINUSE' | ||
console.log "#{'ERROR:'.bold.red} Server port #{port} already in use" | ||
console.log "(maybe another `vtex watch -s` is running?)" | ||
process.exit 1 | ||
.once 'listening', -> | ||
testPort.close() | ||
runDevServer() | ||
.listen 3000 | ||
|
||
startWebpack: => | ||
setTimeout => | ||
@compiler.watch {}, (err, stats) -> | ||
if err | ||
console.error err.stack || err | ||
return | ||
|
||
outputOptions = | ||
cached: false | ||
cachedAssets: false | ||
colors: require 'supports-color' | ||
exclude: ["node_modules", "bower_components", "jam", "components"] | ||
|
||
console.log stats.toString(outputOptions) + '\n' | ||
, @DELAY_TIME | ||
|
||
module.exports = new WebpackOption | ||
|
Oops, something went wrong.