Created
April 9, 2018 20:28
-
-
Save gantoine/e3393933a0ea191655a6ec9647cac276 to your computer and use it in GitHub Desktop.
A Webpack configuration file with style loading
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 { resolve } from 'path'; | |
import ExtractTextPlugin from 'extract-text-webpack-plugin'; | |
const cssLoaders = [ | |
{ loader: 'css-loader' }, | |
{ loader: 'sass-loader' }, | |
{ loader: 'postcss-loader' }, | |
]; | |
const devLoaders = [{ loader: 'style-loader' }].concat(cssLoaders); | |
module.exports = env => { | |
const config = { | |
context: resolve('src/js'), | |
entry: { | |
main: ['babel-polyfill', './app.js'], | |
}, | |
output: { | |
path: resolve('public/dist'), | |
filename: '[name].js', | |
publicPath: '/dist/', | |
}, | |
plugins: [], | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
use: { | |
loader: 'babel-loader', | |
}, | |
}, | |
{ | |
test: /\.hbs$/, | |
use: { | |
loader: 'handlebars-loader', | |
}, | |
}, | |
{ | |
test: /\.scss$/, | |
exclude: /node_modules/, | |
use: env.dev ? devLoaders : ExtractTextPlugin.extract({ | |
fallback: 'style-loader', | |
use: cssLoaders, | |
}) | |
} | |
] | |
}, | |
resolve: { | |
modules: [resolve('./frontend/js')], | |
extensions: ['.js', '.hbs'], | |
} | |
}; | |
if (env.prod) { | |
config.plugins.push(new ExtractTextPlugin({ | |
filename: '[name].css', | |
})); | |
} | |
return config; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment