Skip to content

Instantly share code, notes, and snippets.

@cymen
Created November 23, 2015 00: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 cymen/9aec78c717c352ea0dc2 to your computer and use it in GitHub Desktop.
Save cymen/9aec78c717c352ea0dc2 to your computer and use it in GitHub Desktop.
webpack config with css, etc.
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var commonLoaders = [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader?browsers=last 3 versions')
}, {
test: /\.less$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader?browsers=last 3 versions!less-loader')
}, {
test: /\.sass/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader?browsers=last 3 versions!sass-loader')
}, {
test: /\.scss/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader?browsers=last 3 versions!sass-loader')
},
{
test: /\.js$/,
loaders: ['babel-loader'],
exclude: /node_modules/
}, {
test: /\.json$/,
loaders: ['json-loader']
}
];
var assetsPath = path.join(__dirname, '/dist');
var publicPath = '/app/webpack/dist/';
module.exports = {
name: 'browser',
entry: [
path.join(__dirname, '/node_modules/babel-core/polyfill.js'),
path.join(__dirname, '/src/MyApp.js')
],
output: {
path: assetsPath,
publicPath: publicPath,
filename: 'bundle.js'
},
module: {
loaders: commonLoaders.concat([{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
}, {
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}, {
test: /\.gif/,
loader: 'url-loader?limit=10000&mimetype=image/gif'
}, {
test: /\.jpg/,
loader: 'url-loader?limit=10000&mimetype=image/jpg'
}, {
test: /\.png/,
loader: 'url-loader?limit=10000&mimetype=image/png'
}, {
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
query: {
cacheDirectory: true
}
}])
},
plugins: [
new ExtractTextPlugin('bundle.css', {
allChunks: true
})
]
};
@drewhamlett
Copy link

Thanks for taking the time to put this together! How are you exactly using this with Rails? Or is your front end separated out?

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