Skip to content

Instantly share code, notes, and snippets.

@JesusMurF
Created July 7, 2017 17:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JesusMurF/82ee5737990714dc43a7ee37076eb351 to your computer and use it in GitHub Desktop.
Save JesusMurF/82ee5737990714dc43a7ee37076eb351 to your computer and use it in GitHub Desktop.
Webpack 3
const webpack = require('webpack')
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackPluginConfig = new HtmlWebpackPlugin({
template: path.join(__dirname, './src/index.html'),
filename: 'index.html',
inject: 'body'
})
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
publicPath: '/',
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader'
},
{
test: /\.js?$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader'
},
// CSS loader con CSS Modules
{
test: /\.css$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true
}
}
]
},
// Stylus loader con CSS Modules
{
test: /\.styl$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
},
'stylus-loader'
]
}
]
},
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
hot: true,
inline: true,
historyApiFallback: true,
port: 9000
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
HtmlWebpackPluginConfig
]
}
@arboleya
Copy link

Thanks for the gist, very clarifying about getting stylus & css modules working with Webpack3. 🍻

@shammellee
Copy link

shammellee commented Mar 14, 2018

Thanks so much! Any way to use the default CSS identifiers instead of [name]__[local]___[hash:base64:5]?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment