Created
June 13, 2017 08:21
-
-
Save kutyel/f0ff3cf03d453b7c1368a5ef35d0ea12 to your computer and use it in GitHub Desktop.
Webpack 2 with React, CSS Modules & SASS
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
import webpack from 'webpack'; | |
import { resolve } from 'path'; | |
import ExtractTextPlugin from 'extract-text-webpack-plugin'; | |
import ForceCaseSensitivityPlugin from 'force-case-sensitivity-webpack-plugin'; | |
import autoprefixer from 'autoprefixer'; | |
import getClientEnvironment from './config/env'; | |
const nodeModulesPath = resolve(__dirname, 'node_modules'); | |
const bowerModulesPath = resolve(__dirname, 'bower_components'); | |
const srcPath = resolve(__dirname, 'src'); | |
const buildPath = resolve(__dirname, 'dist'); | |
export default { | |
bail: true, | |
devtool: false, | |
entry: { | |
lucentum: ['./src/lucentum.js'] | |
}, | |
output: { | |
path: buildPath, | |
filename: '[name].js', | |
library: 'lucentum', | |
libraryTarget: 'umd', | |
umdNamedDefine: true | |
}, | |
module: { | |
rules: [ | |
{ | |
test: /\.jsx?$/, | |
enforce: 'pre', | |
loader: 'eslint-loader', | |
include: srcPath | |
}, | |
{ | |
test: /\.jsx?$/, | |
include: srcPath, | |
exclude: [nodeModulesPath, bowerModulesPath], | |
loader: 'babel-loader' | |
}, | |
{ | |
test: /\.s?css$/, | |
use: ExtractTextPlugin.extract({ | |
fallback: 'style-loader', | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { | |
modules: true, | |
importLoaders: 1, | |
localIdentName: '[name]__[local]___[hash:base64:5]' | |
} | |
}, | |
'postcss-loader', | |
'sass-loader' | |
] | |
}) | |
}, | |
{ | |
test: /\.(ico|jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2)(\?.*)?$/, | |
loader: 'file-loader', | |
query: { | |
name: 'media/[name].[ext]' | |
} | |
} | |
] | |
}, | |
plugins: [ | |
new webpack.DefinePlugin(getClientEnvironment('')), | |
new webpack.optimize.UglifyJsPlugin({ mangle: false }), | |
new ExtractTextPlugin({ filename: '[name].css' }), | |
new ForceCaseSensitivityPlugin(), | |
new webpack.LoaderOptionsPlugin({ | |
minimize: true, | |
options: { | |
postcss: [ | |
autoprefixer({ | |
browsers: ['>1%', 'last 4 versions', 'Firefox ESR', 'not ie < 9'] | |
}) | |
] | |
} | |
}) | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment