Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make webpack configuration be templates #34
This closes #34
- Loading branch information
Showing
3 changed files
with
131 additions
and
115 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 |
---|---|---|
@@ -1,53 +1,3 @@ | ||
'use strict'; | ||
|
||
var path = require('path'); | ||
var webpack = require('webpack'); | ||
|
||
module.exports = { | ||
devtool: 'cheap-eval-source-map', | ||
entry: [ | ||
'webpack-hot-middleware/client?reload=true', | ||
path.join(__dirname, 'src/index.js') | ||
], | ||
output: { | ||
path: path.join(__dirname, '/js'), | ||
filename: 'app.min.js', | ||
publicPath: '/js' | ||
}, | ||
plugins: [ | ||
new webpack.optimize.OccurenceOrderPlugin(), | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.NoErrorsPlugin(), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
// This has effect on the react lib size | ||
NODE_ENV: JSON.stringify('development'), | ||
ENABLE_LOGGER: JSON.stringify(process.env.ENABLE_LOGGER), | ||
BUSYWS_HOST: JSON.stringify(process.env.BUSYWS_HOST || 'https://ws.busy6.com'), | ||
IS_BROWSER: JSON.stringify(true), | ||
} | ||
}) | ||
], | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js?$/, | ||
exclude: /node_modules/, | ||
loader: 'babel', | ||
}, | ||
{ | ||
test: /\.json?$/, | ||
loader: 'json', | ||
}, | ||
{ | ||
test: /\.s[ac]ss$/, | ||
loaders: [ | ||
'style', | ||
'css?sourceMap', | ||
'autoprefixer-loader?browsers=last 2 version', | ||
'sass?sourceMap&sourceMapContents', | ||
], | ||
}, | ||
], | ||
}, | ||
}; | ||
module.exports = require('./webpack/makeConfig')({ | ||
isDevelopmen: true | ||
}); |
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 |
---|---|---|
@@ -1,62 +1,3 @@ | ||
'use strict'; | ||
|
||
var ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
var Visualizer = require('webpack-visualizer-plugin'); | ||
var path = require('path'); | ||
var webpack = require('webpack'); | ||
|
||
module.exports = { | ||
devtool: 'source-map', | ||
entry: [ | ||
path.join(__dirname, 'src/index.js') | ||
], | ||
output: { | ||
path: path.join(__dirname, '/public/js'), | ||
filename: 'app.min.js', | ||
publicPath: '/js' | ||
}, | ||
plugins: [ | ||
new webpack.optimize.OccurenceOrderPlugin(), | ||
new webpack.optimize.DedupePlugin(), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
minimize: true, | ||
compress: { | ||
warnings: false, | ||
} | ||
}), | ||
new Visualizer({ | ||
filename: './statistics.html' | ||
}), | ||
new webpack.optimize.AggressiveMergingPlugin(), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
// This has effect on the react lib size | ||
NODE_ENV: JSON.stringify('production'), | ||
ENABLE_LOGGER: JSON.stringify(process.env.ENABLE_LOGGER), | ||
BUSYWS_HOST: JSON.stringify(process.env.BUSYWS_HOST || 'https://ws.busy6.com'), | ||
IS_BROWSER: JSON.stringify(true), | ||
}, | ||
}), | ||
new ExtractTextPlugin('../css/base.css'), | ||
], | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js?$/, | ||
exclude: /node_modules/, | ||
loader: 'babel', | ||
}, | ||
{ | ||
test: /\.json?$/, | ||
loader: 'json', | ||
}, | ||
{ | ||
test: /\.s[ac]ss$/, | ||
loader: ExtractTextPlugin.extract( | ||
'style-loader', | ||
'css!autoprefixer-loader?browsers=last 2 version!sass' | ||
), | ||
}, | ||
], | ||
}, | ||
}; | ||
module.exports = require('./webpack/makeConfig')({ | ||
isDevelopment: false, | ||
}); |
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,125 @@ | ||
'use strict'; | ||
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
const Visualizer = require('webpack-visualizer-plugin'); | ||
const _ = require('lodash'); | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
|
||
const DEFAULTS = { | ||
isDevelopment: process.env.NODE_ENV !== 'production', | ||
baseDir: path.join(__dirname, '..'), | ||
}; | ||
|
||
function makePlugins(options) { | ||
const isDevelopment = options.isDevelopment; | ||
|
||
let plugins = [ | ||
new webpack.optimize.OccurenceOrderPlugin(), | ||
new webpack.DefinePlugin({ | ||
'process.env': { | ||
// This has effect on the react lib size | ||
NODE_ENV: isDevelopment | ||
? JSON.stringify('development') | ||
: JSON.stringify('production'), | ||
ENABLE_LOGGER: JSON.stringify(process.env.ENABLE_LOGGER), | ||
BUSYWS_HOST: JSON.stringify(process.env.BUSYWS_HOST || 'https://ws.busy6.com'), | ||
IS_BROWSER: JSON.stringify(true), | ||
}, | ||
}), | ||
new Visualizer({ | ||
filename: './statistics.html' | ||
}), | ||
]; | ||
|
||
if (isDevelopment) { | ||
plugins = plugins.concat([ | ||
new webpack.optimize.OccurenceOrderPlugin(), | ||
new webpack.HotModuleReplacementPlugin(), | ||
new webpack.NoErrorsPlugin(), | ||
]); | ||
} else { | ||
plugins = plugins.concat([ | ||
new webpack.optimize.DedupePlugin(), | ||
new webpack.optimize.UglifyJsPlugin({ | ||
minimize: true, | ||
compress: { | ||
warnings: false, | ||
} | ||
}), | ||
new webpack.optimize.AggressiveMergingPlugin(), | ||
new ExtractTextPlugin('../css/base.css'), | ||
]); | ||
} | ||
|
||
return plugins; | ||
} | ||
|
||
function makeStyleLoaders(options) { | ||
if (options.isDevelopment) { | ||
return [ | ||
{ | ||
test: /\.s[ac]ss$/, | ||
loaders: [ | ||
'style', | ||
'css?sourceMap', | ||
'autoprefixer-loader?browsers=last 2 version', | ||
'sass?sourceMap&sourceMapContents', | ||
], | ||
}, | ||
]; | ||
} | ||
|
||
return [ | ||
{ | ||
test: /\.s[ac]ss$/, | ||
loader: ExtractTextPlugin.extract( | ||
'style-loader', | ||
'css!autoprefixer-loader?browsers=last 2 version!sass' | ||
), | ||
}, | ||
]; | ||
} | ||
|
||
function makeConfig(options) { | ||
if (!options) options = {}; | ||
_.defaults(options, DEFAULTS); | ||
|
||
const isDevelopment = options.isDevelopment; | ||
|
||
return { | ||
devtool: isDevelopment ? 'cheap-eval-source-map' : 'source-map', | ||
entry: (isDevelopment ? [ | ||
'webpack-hot-middleware/client?reload=true', | ||
] : []).concat([ | ||
path.join(options.baseDir, 'src/index.js') | ||
]), | ||
output: { | ||
path: path.join(options.baseDir, '/public/js'), | ||
filename: 'app.min.js', | ||
publicPath: '/js' | ||
}, | ||
plugins: makePlugins(options), | ||
module: { | ||
loaders: [ | ||
{ | ||
test: /\.js?$/, | ||
exclude: /node_modules/, | ||
loader: 'babel', | ||
}, | ||
{ | ||
test: /\.json?$/, | ||
loader: 'json', | ||
}, | ||
].concat(makeStyleLoaders(options)), | ||
}, | ||
}; | ||
} | ||
|
||
if (!module.parent) { | ||
console.log(makeConfig({ | ||
isDevelopment: process.env.NODE_ENV !== 'production', | ||
})); | ||
} | ||
|
||
exports = module.exports = makeConfig; | ||
exports.DEFAULTS = DEFAULTS; |