Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get under control webpack config files. #691

Merged
merged 1 commit into from May 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 0 additions & 14 deletions ie8/package.json

This file was deleted.

5 changes: 2 additions & 3 deletions package.json
Expand Up @@ -15,8 +15,7 @@
"docs-build": "babel-node tools/build-cli.js --docs-only",
"docs": "docs/dev-run",
"docs-prod": "npm run docs-build && NODE_ENV=production babel-node docs/server.js",
"docs-prod-unoptimized": "npm run docs-build -- --dev && NODE_ENV=production babel-node docs/server.js",
"ie8": "babel-node ie8/server.js"
"docs-prod-unoptimized": "npm run docs-build -- --dev && NODE_ENV=production babel-node docs/server.js"
},
"main": "lib/index.js",
"directories": {
Expand Down Expand Up @@ -87,4 +86,4 @@
"dependencies": {
"classnames": "^2.0.0"
}
}
}
3 changes: 1 addition & 2 deletions webpack.config.js
@@ -1,5 +1,4 @@
/* eslint no-var: 0 */
require('babel/register');
var config = require('./webpack/webpack.config');
var result = config();
module.exports = result;
module.exports = config;
41 changes: 41 additions & 0 deletions webpack/base.config.js
@@ -0,0 +1,41 @@
import webpack from 'webpack';
import yargs from 'yargs';

export const options = yargs
.alias('p', 'optimize-minimize')
.alias('d', 'debug')
.option('port', {
default: '8080',
type: 'string'
})
.argv;

export const jsLoader = 'babel';

const baseConfig = {
entry: undefined,

output: undefined,

externals: undefined,

module: {
loaders: [
{ test: /\.js/, loader: jsLoader, exclude: /node_modules/ }
]
},

plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(options.optimizeMinimize ? 'production' : 'development')
}
})
]
};

if (options.optimizeMinimize) {
baseConfig.devtool = 'source-map';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be in the object declation above as: devtool: argv.optimizeMinimize ? 'source-map' : undefined

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This came up before, but I also like eval-source-map - lets you see the original ES6 code, and is a lot faster when running in "watch" mode than normal source maps. I think we saw that it didn't properly map traceback lines in some cases, though.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That was specifically in failure stack traces when running tests in karma. I didn't try the browser though. Either way the webpack/test.config would override with what's needed there: https://github.com/react-bootstrap/react-bootstrap/pull/691/files#diff-0a73b4c419b2170092ad0f940a3bdc83R9

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change
devtool: 'eval' for tests
into
devtool: 'eval-source-map'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

devtool for tests needs to be eval or else failure stack traces don't work. @taion Is proposing that this devtool should be eval-source-map and I'm inclined to agree.


export default baseConfig;
59 changes: 44 additions & 15 deletions webpack/docs.config.js
@@ -1,18 +1,47 @@
import config from './webpack.config';
import yargs from 'yargs';
import _ from 'lodash';
import webpack from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import baseConfig, { options, jsLoader } from './base.config';

const argv = yargs
.alias('p', 'optimize-minimize')
.alias('d', 'debug')
.option('port', {
default: '8080',
type: 'string'
})
.argv;
const webpackDevServerAddress = `http://localhost:${options.port}`;
const cssSourceMap = options.debug ? '?sourceMap' : '';
const reactHot = options.debug ? 'react-hot!' : '';

export default config({
docs: true,
development: argv.debug,
optimize: argv.optimizeMinimize,
port: parseInt(argv.port)
const entryFile = './docs/client.js';
const devEntryBundle = [
'webpack/hot/dev-server',
`webpack-dev-server/client?${webpackDevServerAddress}`,
entryFile
];

baseConfig.plugins.push(new ExtractTextPlugin('[name].css'));
if (options.debug) {
baseConfig.plugins.push(new webpack.NoErrorsPlugin());
}

export default _.extend({}, baseConfig, {
entry: {
bundle: options.debug ? devEntryBundle : entryFile
},

output: {
filename: '[name].js',
path: './docs-built/assets',
publicPath: options.debug ? `${webpackDevServerAddress}/assets/` : '/assets/'
},

module: {
noParse: /babel-core\/browser/,
loaders: [
{ test: /\.js/, loader: `${reactHot}${jsLoader}`, exclude: /node_modules|Samples\.js/ },
{ test: /Samples.js/, loader: `${reactHot}transform?brfs!${jsLoader}` },
{ test: /\.css/,
loader: ExtractTextPlugin.extract('style', `css${cssSourceMap}`) },
{ test: /\.less$/,
loader: ExtractTextPlugin.extract('style', `css${cssSourceMap}!less${cssSourceMap}`) },
{ test: /\.json$/, loader: 'json' },
{ test: /\.jpe?g$|\.gif$|\.png|\.ico$/, loader: 'file?name=[name].[ext]' },
{ test: /\.eot$|\.ttf$|\.svg$|\.woff2?$/, loader: 'file?name=[name].[ext]' }
]
}
});
13 changes: 0 additions & 13 deletions webpack/strategies/development.js

This file was deleted.

40 changes: 0 additions & 40 deletions webpack/strategies/docs-development.js

This file was deleted.

55 changes: 0 additions & 55 deletions webpack/strategies/docs.js

This file was deleted.

26 changes: 0 additions & 26 deletions webpack/strategies/ie8.js

This file was deleted.

15 changes: 0 additions & 15 deletions webpack/strategies/index.js

This file was deleted.

17 changes: 0 additions & 17 deletions webpack/strategies/optimize.js

This file was deleted.

18 changes: 0 additions & 18 deletions webpack/strategies/test.js

This file was deleted.

11 changes: 9 additions & 2 deletions webpack/test.config.js
@@ -1,3 +1,10 @@
import config from './webpack.config';
import _ from 'lodash';
import baseConfig from './base.config';

export default config({test: true});
export default _.extend({}, baseConfig, {
output: {
pathinfo: true
},

devtool: 'eval'
});