Skip to content

Commit 63d0a1f

Browse files
nfourbrendo
authored andcommitted
Feature/webpack (#107)
* Rewrite webpack configs, add dashboard plugin as well * Add error handling for getDefinition * Update build deps
1 parent 66e3e09 commit 63d0a1f

File tree

6 files changed

+603
-132
lines changed

6 files changed

+603
-132
lines changed

package.json

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
}
1717
],
1818
"scripts": {
19-
"start": "webpack-dev-server",
19+
"start": "webpack-dev-server --config ./webpack.config.dev.js",
20+
"dash": "webpack-dashboard -- yarn start",
2021
"lint": "eslint src test",
2122
"test": "jest",
2223
"test:coverage": "jest --coverage",
@@ -50,16 +51,16 @@
5051
"superagent": "^3.5.2"
5152
},
5253
"devDependencies": {
53-
"babel-core": "^6.24.0",
54+
"babel-core": "^6.25.0",
5455
"babel-eslint": "^7.2.1",
5556
"babel-jest": "^20.0.3",
56-
"babel-loader": "^6.4.1",
57+
"babel-loader": "^7.0.0",
5758
"babel-polyfill": "^6.23.0",
5859
"babel-preset-es2015": "^6.24.0",
5960
"babel-preset-react": "^6.23.0",
6061
"babel-preset-stage-1": "^6.22.0",
6162
"balloon-css": "^0.4.0",
62-
"css-loader": "^0.27.3",
63+
"css-loader": "^0.28.4",
6364
"eslint": "^3.19.0",
6465
"eslint-config-standard": "^10.2.1",
6566
"eslint-config-standard-react": "^5.0.0",
@@ -68,18 +69,20 @@
6869
"eslint-plugin-promise": "^3.5.0",
6970
"eslint-plugin-react": "^7.0.1",
7071
"eslint-plugin-standard": "^3.0.1",
71-
"extract-text-webpack-plugin": "^2.1.0",
72-
"file-loader": "^0.11.1",
72+
"extract-text-webpack-plugin": "^2.1.2",
73+
"file-loader": "^0.11.2",
7374
"fs-extra": "^3.0.1",
7475
"html-webpack-plugin": "^2.28.0",
7576
"jest": "^20.0.4",
7677
"json-loader": "^0.5.4",
7778
"node-sass": "^4.5.1",
7879
"react-addons-perf": "^15.4.2",
80+
"react-dev-utils": "^3.0.0",
7981
"react-test-renderer": "^15.5.4",
8082
"sass-loader": "^6.0.3",
81-
"style-loader": "^0.16.0",
82-
"webpack": "^2.3.2",
83+
"style-loader": "^0.18.2",
84+
"webpack": "^2.6.1",
85+
"webpack-dashboard": "^0.4.0",
8386
"webpack-dev-server": "^2.4.2",
8487
"webpack-merge": "^4.1.0"
8588
}

src/store/definition/actions.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ function parseDefinitionFailure (error) {
3434
}
3535

3636
export default function getDefinition (url, parserType) {
37+
if (!url) { throw new Error('getDefinition called without a url') }
38+
3739
return (dispatch) => {
3840
request
3941
.get(url)

webpack.config.dev.js

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1-
module.exports = () => {
2-
return {
3-
devtool: 'source-map',
4-
devServer: {
5-
contentBase: `${__dirname}/src`,
6-
compress: false,
7-
port: 8200,
8-
historyApiFallback: true
9-
},
10-
output: {
11-
path: `${__dirname}/src`
12-
}
13-
};
14-
};
1+
const DashboardPlugin = require('webpack-dashboard/plugin')
2+
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin')
3+
const webpackMerge = require('webpack-merge')
4+
const baseConfig = require('./webpack.config')
5+
6+
console.log('\nwebpack.config.dev\n')
7+
8+
module.exports = webpackMerge(baseConfig, {
9+
plugins: [
10+
new DashboardPlugin(),
11+
new WatchMissingNodeModulesPlugin(`${__dirname}/node_modules`)
12+
],
13+
14+
devtool: 'source-map',
15+
16+
devServer: {
17+
contentBase: './src',
18+
compress: false,
19+
port: 8200,
20+
historyApiFallback: true,
21+
watchOptions: { aggregateTimeout: 100 },
22+
stats: { chunkModules: false }
23+
},
24+
25+
output: { path: `${__dirname}/src` }
26+
})

webpack.config.js

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,85 +1,94 @@
1-
const webpackMerge = require('webpack-merge');
2-
const ExtractTextPlugin = require('extract-text-webpack-plugin');
3-
const HtmlWebpackPlugin = require('html-webpack-plugin');
4-
const devConfig = require('./webpack.config.dev');
5-
const pkgJson = require('./package.json');
1+
const webpack = require('webpack')
2+
const HtmlWebpackPlugin = require('html-webpack-plugin')
3+
const pkgJson = require('./package.json')
4+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
65

7-
const isProduction = PRODUCTION = process.env.NODE_ENV === 'prod';
6+
const isProduction = process.env.NODE_ENV === 'prod'
87

98
const extractSass = new ExtractTextPlugin({
10-
filename: "bundle.css",
9+
filename: 'bundle.css',
1110
disable: !isProduction
12-
});
11+
})
1312

14-
let webpackConfig = {
13+
module.exports = {
1514
context: `${__dirname}/src`,
1615
entry: {
17-
bundle: [
18-
'./index.js'
19-
],
16+
bundle: ['core-js/es7', './index.js'],
2017

2118
// Everything in the `dependencies` should be considered a `vendor` library
22-
vendor: [].concat(Object.keys(pkgJson.dependencies))
19+
vendor: [
20+
'core-js/es7'
21+
].concat(Object.keys(pkgJson.dependencies))
2322
},
2423
output: {
2524
path: `${__dirname}/dist`,
2625
publicPath: '/',
2726
filename: '[name].[chunkhash].js'
2827
},
29-
30-
resolve: {
31-
modules: ['src/', 'node_modules'],
32-
extensions: ['.js', '.jsx', '.json']
33-
},
3428
plugins: [
3529
extractSass,
30+
31+
new webpack.optimize.CommonsChunkPlugin({
32+
names: ['vendor', 'manifest']
33+
}),
34+
3635
/**
3736
* This renders out an `./dist/index.html` with all scripts, title etc. attached
3837
*/
3938
new HtmlWebpackPlugin({
4039
title: pkgJson.description || pkgJson.name,
4140
filename: 'index.html',
4241
template: './index.html'
42+
}),
43+
44+
new webpack.DefinePlugin({
45+
'process.env': {
46+
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
47+
}
4348
})
4449
],
50+
resolve: {
51+
modules: ['src/', 'node_modules'],
52+
extensions: ['.js', '.jsx', '.json']
53+
},
54+
performance: { hints: false },
55+
node: {
56+
fs: 'empty'
57+
},
4558
module: {
4659
rules: [
60+
// JS
4761
{
48-
test: /\.js?/,
49-
exclude: /node_modules/,
50-
loader: 'babel-loader'
62+
test: /\.jsx?$/,
63+
loader: 'babel-loader',
64+
exclude: [/node_modules/]
5165
},
66+
67+
// JSON
5268
{
5369
test: /\.json$/,
5470
loader: 'json-loader'
5571
},
72+
73+
// SASS/CSS
5674
{
5775
test: /\.(css|scss)$/,
5876
use: extractSass.extract({
5977
use: [{
60-
loader: "css-loader"
78+
loader: 'css-loader'
6179
}, {
62-
loader: "sass-loader"
80+
loader: 'sass-loader'
6381
}],
6482
// use style-loader in development
65-
fallback: "style-loader"
83+
fallback: 'style-loader'
6684
})
6785
},
86+
87+
// ASSETS
6888
{
6989
test: /\.(ttf|eot|svg|png|gif|jpg|ico)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
7090
loader: 'file-loader'
7191
}
7292
]
73-
},
74-
node: {
75-
fs: 'empty'
7693
}
77-
};
78-
79-
if (!isProduction) {
80-
webpackConfig = webpackMerge(webpackConfig, devConfig());
8194
}
82-
83-
module.exports = () => {
84-
return webpackConfig;
85-
};

webpack.config.prod.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)