accounts-frontend/webpack.config.js

174 lines
4.7 KiB
JavaScript
Raw Normal View History

/* eslint-env node */
var path = require('path');
var webpack = require('webpack');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var HtmlWebpackPlugin = require('html-webpack-plugin');
2016-01-03 14:41:08 +05:30
var cssnano = require('cssnano');
var iconfontImporter = require('./webpack/node-sass-iconfont-importer');
const API_HOST = 'http://account.l';
2016-01-08 18:44:11 +05:30
/**
* TODO: https://babeljs.io/docs/plugins/
* TODO: отдельные конфиги для env (аля https://github.com/davezuko/react-redux-starter-kit)
* https://github.com/glenjamin/ultimate-hot-reloading-example ( обратить внимание на плагины babel )
* https://github.com/gajus/react-css-modules ( + BrowserSync)
*
* Inspiration projects:
* https://github.com/davezuko/react-redux-starter-kit
*/
var isProduction = process.argv.some(function(arg) {
return arg === '-p';
});
var isTest = process.argv.some(function(arg) {
return arg.indexOf('karma') !== -1;
});
var webpackConfig = {
entry: {
app: path.join(__dirname, 'src'),
vendor: [
'history',
'react',
'react-redux',
'react-router',
'redux-simple-router',
'redux',
// I18n
'intl-format-cache',
'intl-messageformat'
]
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js'
},
resolve: {
root: path.resolve('./src'),
extensions: ['', '.js', '.jsx']
},
devServer: {
host: 'localhost',
port: 8080,
proxy: {
'/api*': {
target: API_HOST
}
},
hot: true,
inline: true,
historyApiFallback: true
},
devtool: isTest ? 'inline-source-map' : 'eval',
plugins: [
new iconfontImporter.Plugin(),
new webpack.DefinePlugin({
'process.env': {
2016-01-08 18:44:11 +05:30
NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development')
},
__DEV__: !isProduction,
__TEST__: isTest,
__PROD__: isProduction
}),
new HtmlWebpackPlugin({
template: 'src/index.html',
favicon: 'src/favicon.ico',
hash: isProduction,
filename: 'index.html',
inject: 'body',
minify: {
collapseWhitespace: isProduction
}
})
].concat(isTest ? [] : [
new webpack.optimize.CommonsChunkPlugin('vendor', 'vendor.js')
]).concat(isProduction ? [
new webpack.optimize.DedupePlugin(),
new webpack.optimize.UglifyJsPlugin()
] : []),
module: {
loaders: [
{
test: /\.scss$/,
extractInProduction: true,
loader: 'style!css?modules&importLoaders=2&localIdentName[=path][name]-[local]!postcss!sass'
},
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel',
query: {
presets: ['react', 'es2015', 'stage-0'],
2016-01-08 18:44:11 +05:30
plugins: ['transform-runtime', ['react-intl', {messagesDir: './dist/messages/'}]],
env: {
development: {
presets: ['react-hmre']
}
}
}
}
]
2016-01-03 14:41:08 +05:30
},
sassLoader: {
importer: iconfontImporter({
test: /\.font.(js|json)$/,
types: ['woff', 'eot', 'ttf']
})
},
2016-01-03 14:41:08 +05:30
postcss: [
cssnano({
sourcemap: !isProduction,
autoprefixer: {
add: true,
remove: true,
browsers: ['last 2 versions']
},
safe: true,
// отключаем минификацию цветов, что бы она не ломала такие выражения:
// composes: black from './buttons.scss';
colormin: false,
2016-01-03 14:41:08 +05:30
discardComments: {
removeAll: true
}
})
]
};
if (isProduction) {
2016-01-08 18:44:11 +05:30
webpackConfig.module.loaders.forEach((loader) => {
if (loader.extractInProduction) {
var parts = loader.loader.split('!');
loader.loader = ExtractTextPlugin.extract(parts[0], parts.slice(1).join('!'));
}
});
2016-01-03 14:41:08 +05:30
webpackConfig.plugins.push(new ExtractTextPlugin('styles.css', {
allChunks: true
}));
webpackConfig.devtool = false;
}
2016-01-08 18:44:11 +05:30
if (!isProduction && !isTest) {
webpackConfig.plugins.push(
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
);
}
module.exports = webpackConfig;