Created
June 29, 2017 14:25
-
-
Save SergProduction/fc2ed02e514886f70a1432b4168b6951 to your computer and use it in GitHub Desktop.
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
const path = require('path') | |
const webpack = require('webpack') | |
const UglifyJSPlugin = require('uglifyjs-webpack-plugin') | |
const ExtractTextPlugin = require('extract-text-webpack-plugin') | |
const prod = process.env.NODE_ENV === 'prod' | |
const extractStylus = new ExtractTextPlugin('../css/[name].css') | |
const webpackConfig = { | |
context: __dirname, | |
entry: { | |
base: './src/base', | |
}, | |
output: { | |
path: path.join(__dirname, '/public/js'), | |
filename: '[name].js', | |
library: '[name]', | |
}, | |
watch: true, | |
resolve: { | |
moduleExtensions: ['.', './node_modules'], | |
extensions: ['.js', '.jsx'], | |
}, | |
devtool: 'eval', | |
module: { | |
rules: [ | |
{ | |
test: /\.jsx?$/, | |
exclude: /(node_modules)/, | |
loader: 'babel-loader', | |
options: { | |
presets: ['es2015', 'react'], | |
plugins: [ | |
'transform-class-properties', | |
'transform-object-rest-spread', | |
], | |
}, | |
}, | |
{ | |
test: /\.styl$/, | |
exclude: /(node_modules)/, | |
use: extractStylus.extract({ | |
fallback: 'style-loader', | |
use: ['css-loader', 'stylus-loader'], | |
}), | |
}, | |
], | |
}, | |
plugins: [ | |
new webpack.ProvidePlugin({ | |
React: 'react', | |
}), | |
extractStylus, | |
], | |
devServer: { | |
contentBase: [ | |
path.join(__dirname, 'public/'), | |
], | |
publicPath: '/js/', | |
watchContentBase: true, | |
compress: true, | |
port: 3000, | |
}, | |
} | |
if (prod) { | |
delete webpackConfig.devServer | |
delete webpackConfig.devtool | |
webpackConfig.watch = false | |
webpackConfig.module.rules[0].options.plugins.push('transform-react-remove-prop-types') | |
webpackConfig.plugins.concat([ | |
new UglifyJSPlugin(), | |
new webpack.DefinePlugin({ | |
'process.env': { | |
NODE_ENV: JSON.stringify('production'), | |
}, | |
}), | |
]) | |
} | |
module.exports = webpackConfig |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment