From e95510dbed9f9871a22e7de31c1c08ab030377da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jose=CC=81=20Magalha=CC=83es?= Date: Mon, 16 Nov 2015 00:30:35 +0000 Subject: [PATCH] ongoing webpack integration #71 --- .babelrc | 6 +++- .relaxrc.sample | 1 + config.js | 1 + index.js | 1 - lib/components/dnd/droppable.jsx | 8 ++--- package.json | 17 +++++++--- webpack.config.js | 58 ++++++++++++++++++++++++++++++++ webpack.server.js | 18 ++++++++++ 8 files changed, 100 insertions(+), 10 deletions(-) create mode 100644 webpack.config.js create mode 100644 webpack.server.js diff --git a/.babelrc b/.babelrc index b0b9a96ef..974a1ca3b 100644 --- a/.babelrc +++ b/.babelrc @@ -1,3 +1,7 @@ { - "stage": 0 + "presets": [ + "es2015", + "stage-0", + "react" + ] } diff --git a/.relaxrc.sample b/.relaxrc.sample index 4199e0e14..34432fc04 100644 --- a/.relaxrc.sample +++ b/.relaxrc.sample @@ -1,5 +1,6 @@ { "port": 8080, + "devPort": 8181, "db": { "uri": "mongodb://localhost/relax" } diff --git a/config.js b/config.js index d8c0d2b3a..2fe6be7b4 100644 --- a/config.js +++ b/config.js @@ -2,6 +2,7 @@ import rc from 'rc'; export default rc('relax', { port: 8080, + devPort: 8181, db: { uri: 'mongodb://localhost/relax' } diff --git a/index.js b/index.js index 7770eb2fd..4cd59214a 100644 --- a/index.js +++ b/index.js @@ -1,2 +1 @@ -require('babel/register'); require('./app'); diff --git a/lib/components/dnd/droppable.jsx b/lib/components/dnd/droppable.jsx index badd49048..66b8beaa7 100644 --- a/lib/components/dnd/droppable.jsx +++ b/lib/components/dnd/droppable.jsx @@ -278,15 +278,15 @@ export default class Droppable extends Component { hasChildren () { const children = this.props.children; - let hasChildren = false; + var _hasChildren = false; if (children) { if (children instanceof Array) { - hasChildren = children.length > 0; + _hasChildren = children.length > 0; } else if (children instanceof Object) { - hasChildren = true; + _hasChildren = true; } } - return hasChildren; + return _hasChildren; } showMarks () { diff --git a/package.json b/package.json index 249f75dbe..8c4123e1d 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,7 @@ "watch": "grunt watch" }, "dependencies": { - "babel": "^5.8.23", + "babel": "^6.1.18", "blueimp-md5": "^1.1.1", "body-parser": "^1.13.3", "classnames": "^2.1.3", @@ -85,9 +85,14 @@ "winston": "^2.1.0" }, "devDependencies": { + "autoprefixer-loader": "^3.1.0", + "babel-core": "^6.1.21", "babel-eslint": "^4.1.3", - "babel-runtime": "^5.8.25", - "babelify": "^6.3.0", + "babel-loader": "^6.1.0", + "babel-preset-es2015": "^6.1.18", + "babel-preset-react": "^6.1.18", + "babel-preset-stage-0": "^6.1.18", + "babelify": "^7.2.0", "eslint": "^1.6.0", "eslint-config-relax": "^1.0.5", "eslint-plugin-react": "^3.5.1", @@ -99,11 +104,15 @@ "grunt-contrib-uglify": "^0.10.0", "grunt-contrib-watch": "^0.6.1", "grunt-nodemon": "^0.4.0", + "less-loader": "^2.2.1", "less-plugin-autoprefix": "^1.4.2", "less-plugin-clean-css": "^1.5.1", "nodemon": "^1.8.1", "redux-devtools": "^3.0.0-beta-3", - "redux-immutable-state-invariant": "^1.1.1" + "redux-immutable-state-invariant": "^1.1.1", + "webpack": "^1.12.6", + "webpack-dev-server": "^1.12.1", + "webpack-hot-middleware": "^2.5.0" }, "apps": [ { diff --git a/webpack.config.js b/webpack.config.js new file mode 100644 index 000000000..1166d1bcf --- /dev/null +++ b/webpack.config.js @@ -0,0 +1,58 @@ +import {join} from 'path'; +import { + HotModuleReplacementPlugin, + NoErrorsPlugin, + DefinePlugin, + optimize +} from 'webpack'; + +import config from './config'; + +// import babelConfig from './.babelrc'; + +module.exports = { + // devtool: 'eval', + entry: { + admin: join(__dirname, '/lib/client/admin.js'), + auth: join(__dirname, '/lib/client/auth.js'), + public: join(__dirname, '/lib/client/public.js'), + // devServer: `webpack-dev-server/client?http://0.0.0.0:${config.devPort}`, + // hotPlug: 'webpack/hot/only-dev-server', + // server: join(__dirname, 'index.js') + }, + output: { + path: join(__dirname, '/public'), + filename: '[name].js' + }, + resolve: { + extensions: ['', '.js', '.jsx'] + }, + plugins: [ + new optimize.OccurenceOrderPlugin(), + new optimize.CommonsChunkPlugin('common.js', ['admin', 'auth', 'public']), + // new HotModuleReplacementPlugin(), + new NoErrorsPlugin(), + // new DefinePlugin({ + // __DEVELOPMENT__: true, + // __DEVTOOLS__: false + // }) + ], + module: { + loaders: [ + { + test: /\.(js|jsx)$/, + // include: [join(__dirname, 'index.js'), join(__dirname, 'lib')], + loader: 'babel', + exclude: /node_modules/, + query: { + cacheDirectory: true + } + }, + // { + // test: /\.(less|css)$/, + // include: [join(__dirname, 'assets/less')], + // loader: 'style!css!less!autoprefixer' + // } + ] + } +}; diff --git a/webpack.server.js b/webpack.server.js new file mode 100644 index 000000000..aaa474c5e --- /dev/null +++ b/webpack.server.js @@ -0,0 +1,18 @@ +import path from 'path'; +import webpack from 'webpack'; +import WebpackDevServer from 'webpack-dev-server'; + +import config from './config'; +import webpackConfig from './webpack.config'; + +new WebpackDevServer(webpack(webpackConfig), { + contentBase: path.resolve(__dirname, 'public'), + hot: true, + historyApiFallback: true +}) + .listen(config.devPort, '0.0.0.0', (err, result) => { + if (err) { + console.log(err); + } + console.log('Listening at localhost:8080'); + });