From 2a1d7f6b8d365441d27427b6f1ea777bbadb22e5 Mon Sep 17 00:00:00 2001 From: AlexKVal Date: Sun, 17 May 2015 20:57:40 +0300 Subject: [PATCH] Simplify webpack config files. Remove some stale `IE8` pieces. --- ie8/package.json | 14 ----- package.json | 5 +- webpack.config.js | 3 +- webpack/base.config.js | 41 +++++++++++++ webpack/docs.config.js | 59 +++++++++++++----- webpack/strategies/development.js | 13 ---- webpack/strategies/docs-development.js | 40 ------------ webpack/strategies/docs.js | 55 ----------------- webpack/strategies/ie8.js | 26 -------- webpack/strategies/index.js | 15 ----- webpack/strategies/optimize.js | 17 ------ webpack/strategies/test.js | 18 ------ webpack/test.config.js | 11 +++- webpack/webpack.config.js | 85 ++++++++------------------ 14 files changed, 121 insertions(+), 281 deletions(-) delete mode 100644 ie8/package.json create mode 100644 webpack/base.config.js delete mode 100644 webpack/strategies/development.js delete mode 100644 webpack/strategies/docs-development.js delete mode 100644 webpack/strategies/docs.js delete mode 100644 webpack/strategies/ie8.js delete mode 100644 webpack/strategies/index.js delete mode 100644 webpack/strategies/optimize.js delete mode 100644 webpack/strategies/test.js diff --git a/ie8/package.json b/ie8/package.json deleted file mode 100644 index b2b6af9de5..0000000000 --- a/ie8/package.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "dependencies": { - "browserify": "^4.1.11", - "reactify": "^0.13.1", - "envify": "^1.2.1", - "react": "^0.13.0", - "http-server": "^0.6.1" - }, - "scripts": { - "postinstall": "npm run build", - "start": "http-server -c-1", - "build": "grunt --gruntfile ../Gruntfile.js && browserify -t reactify src.js > bundle.js --harmony" - } -} diff --git a/package.json b/package.json index 66cb8e9487..68faa299ff 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -87,4 +86,4 @@ "dependencies": { "classnames": "^2.0.0" } -} \ No newline at end of file +} diff --git a/webpack.config.js b/webpack.config.js index de154a31f9..9d7bf6d0f3 100644 --- a/webpack.config.js +++ b/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; diff --git a/webpack/base.config.js b/webpack/base.config.js new file mode 100644 index 0000000000..f059fd1b12 --- /dev/null +++ b/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'; +} + +export default baseConfig; diff --git a/webpack/docs.config.js b/webpack/docs.config.js index b5d2353634..3545d7534f 100644 --- a/webpack/docs.config.js +++ b/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]' } + ] + } }); diff --git a/webpack/strategies/development.js b/webpack/strategies/development.js deleted file mode 100644 index 6c01d981d0..0000000000 --- a/webpack/strategies/development.js +++ /dev/null @@ -1,13 +0,0 @@ -import _ from 'lodash'; - -export default (config, options) => { - if (options.development && !options.docs) { - config = _.extend({}, config, { - devtool: 'sourcemap' - }); - - return config; - } - - return config; -}; diff --git a/webpack/strategies/docs-development.js b/webpack/strategies/docs-development.js deleted file mode 100644 index 01e1d39319..0000000000 --- a/webpack/strategies/docs-development.js +++ /dev/null @@ -1,40 +0,0 @@ -import _ from 'lodash'; -import webpack from 'webpack'; - -function addWebpackDevServerScripts(entries, webpackDevServerAddress) { - let clientScript = `webpack-dev-server/client?${webpackDevServerAddress}`; - let webpackScripts = ['webpack/hot/dev-server', clientScript]; - return _.mapValues(entries, entry => webpackScripts.concat(entry)); -} - -export default (config, options) => { - if (options.development && options.docs) { - let webpackDevServerAddress = `http://localhost:${options.port}`; - config = _.extend({}, config, { - entry: addWebpackDevServerScripts(config.entry, webpackDevServerAddress), - output: _.extend({}, config.output, { - publicPath: `${webpackDevServerAddress}/assets/` - }), - module: _.extend({}, config.module, { - loaders: config.module.loaders.map(value => { - if (/\.js\/$/.test(value.test.toString())) { - return _.extend({}, value, { - loader: 'react-hot!' + value.loader - }); - } - else { - return value; - } - }) - }), - // Remove extract text plugin from dev workflow so hot reload works on css. - plugins: config.plugins.concat([ - new webpack.NoErrorsPlugin() - ]) - }); - - return config; - } - - return config; -}; diff --git a/webpack/strategies/docs.js b/webpack/strategies/docs.js deleted file mode 100644 index dcc35742f1..0000000000 --- a/webpack/strategies/docs.js +++ /dev/null @@ -1,55 +0,0 @@ -import _ from 'lodash'; -import ExtractTextPlugin from 'extract-text-webpack-plugin'; - -export default (config, options) => { - if (options.docs) { - let jsLoader = ''; - let cssSourceMap = options.development ? '?sourceMap' : ''; - - config = _.extend({}, config, { - entry: { - bundle: './docs/client.js' - }, - output: { - filename: '[name].js', - path: './docs-built/assets', - publicPath: '/assets/' - }, - externals: undefined, - resolve: { - extensions: ['', '.js', '.json'] - }, - module: { - noParse: /babel-core\/browser/, - loaders: config.module.loaders - .map(value => { - if (/\.js\/$/.test(value.test.toString())) { - jsLoader = value.loader; - - return _.extend({}, value, { - exclude: /node_modules|Samples\.js/ - }); - } - - return value; - }) - .concat([ - { test: /Samples.js/, loader: '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]' } - ]) - }, - plugins: config.plugins.concat([ - new ExtractTextPlugin('[name].css') - ]) - }); - - return config; - } - - return config; -}; diff --git a/webpack/strategies/ie8.js b/webpack/strategies/ie8.js deleted file mode 100644 index 0a320c98df..0000000000 --- a/webpack/strategies/ie8.js +++ /dev/null @@ -1,26 +0,0 @@ -import _ from 'lodash'; - -export default (config, options) => { - if (options.ie8) { - config = _.extend({}, config, { - entry: { - bundle: './ie8/src.js' - }, - output: { - filename: '[name].js', - path: './ie8-built/assets', - publicPath: '/assets/' - }, - externals: undefined, - module: { - loaders: config.module.loaders.concat([ - { test: /\.jpe?g$|\.gif$|\.png$/, loader: 'file?name=[name].[ext]' } - ]) - } - }); - - return config; - } - - return config; -}; diff --git a/webpack/strategies/index.js b/webpack/strategies/index.js deleted file mode 100644 index 0f5788b09c..0000000000 --- a/webpack/strategies/index.js +++ /dev/null @@ -1,15 +0,0 @@ -import development from './development'; -import docs from './docs'; -import docsDevelopment from './docs-development'; -import ie8 from './ie8'; -import optimize from './optimize'; -import test from './test'; - -export default [ - optimize, - docs, - ie8, - development, - docsDevelopment, - test -]; diff --git a/webpack/strategies/optimize.js b/webpack/strategies/optimize.js deleted file mode 100644 index 03278c106c..0000000000 --- a/webpack/strategies/optimize.js +++ /dev/null @@ -1,17 +0,0 @@ -import _ from 'lodash'; - -export default (config, options) => { - if (options.optimize) { - config = _.extend({}, config, { - output: _.extend({}, config.output, { - filename: '[name].min.js' - }), - - devtool: 'source-map' - }); - - return config; - } - - return config; -}; diff --git a/webpack/strategies/test.js b/webpack/strategies/test.js deleted file mode 100644 index f95cbbbc34..0000000000 --- a/webpack/strategies/test.js +++ /dev/null @@ -1,18 +0,0 @@ -import _ from 'lodash'; - -export default (config, options) => { - if (options.test) { - config = _.extend({}, config, { - devtool: 'eval', - entry: undefined, - output: { - pathinfo: true - }, - externals: undefined - }); - - return config; - } - - return config; -}; diff --git a/webpack/test.config.js b/webpack/test.config.js index d287d60533..3d3f62730e 100644 --- a/webpack/test.config.js +++ b/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' +}); diff --git a/webpack/webpack.config.js b/webpack/webpack.config.js index 49fe0dd261..b68925c2bc 100644 --- a/webpack/webpack.config.js +++ b/webpack/webpack.config.js @@ -1,63 +1,26 @@ import _ from 'lodash'; -import webpack from 'webpack'; -import strategies from './strategies'; -import yargs from 'yargs'; - -const argv = yargs - .alias('p', 'optimize-minimize') - .alias('d', 'debug') - .argv; - -const defaultOptions = { - development: argv.debug, - docs: false, - test: false, - optimize: argv.optimizeMinimize -}; - -export default (options) => { - options = _.merge({}, defaultOptions, options); - const environment = options.optimize ? 'production' : 'development'; - - const config = { - entry: { - 'react-bootstrap': './src/index.js' - }, - - output: { - path: './dist', - filename: '[name].js', - library: 'ReactBootstrap', - libraryTarget: 'umd' - }, - - externals: [ - { - 'react': { - root: 'React', - commonjs2: 'react', - commonjs: 'react', - amd: 'react' - } +import baseConfig, { options } from './base.config'; + +export default _.extend({}, baseConfig, { + entry: { + 'react-bootstrap': './src/index.js' + }, + + output: { + path: './dist', + filename: options.optimizeMinimize ? '[name].min.js' : '[name].js', + library: 'ReactBootstrap', + libraryTarget: 'umd' + }, + + externals: [ + { + 'react': { + root: 'React', + commonjs2: 'react', + commonjs: 'react', + amd: 'react' } - ], - - module: { - loaders: [ - { test: /\.js/, loader: 'babel', exclude: /node_modules/ } - ] - }, - - plugins: [ - new webpack.DefinePlugin({ - 'process.env': { - 'NODE_ENV': JSON.stringify(environment) - } - }) - ] - }; - - return strategies.reduce((conf, strategy) => { - return strategy(conf, options); - }, config); -}; + } + ] +});