Skip to content

Instantly share code, notes, and snippets.

@jamesmosier
Created January 11, 2017 20:30
Show Gist options
  • Save jamesmosier/7b77b27cf91cf395debcd936f1e05dac to your computer and use it in GitHub Desktop.
Save jamesmosier/7b77b27cf91cf395debcd936f1e05dac to your computer and use it in GitHub Desktop.
webpack config
'use strict';
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const path = require('path');
const resolve = path.resolve;
const rootDir = resolve(__dirname);
const dist = resolve(rootDir, 'appname/secured_assets');
const assetIndex = resolve(rootDir, 'src/app');
const vendorIndex = resolve(rootDir, 'webpack.vendor.js');
const styleIndex = resolve(rootDir, 'webpack.style.js');
const fontPath = '../static/fonts/';
module.exports = {
performance: {
hints: false,
},
watchOptions: {
poll: 3000,
aggregateTimeout: 1000,
},
entry: {
app: assetIndex,
style: styleIndex,
vendor: vendorIndex,
},
output: {
path: dist,
filename: '[name].js',
publicPath: '../',
},
module: {
loaders: [
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
{
loader: 'postcss-loader',
},
]
}),
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallbackLoader: 'style-loader',
loader: [
{
loader: 'css-loader',
query: {
sourceMap: true,
options: {
importLoaders: 2,
},
},
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
query: {
sourceMap: true,
},
},
]
})
},
{
test: /\.html$/,
loaders: 'html-loader',
},
{
test: /\.(gif|png)$/,
loaders: [
{
loader: 'url-loader',
query: {
mimetype: 'image/png'
},
},
],
},
{
test: /\.js/,
loaders: 'babel-loader',
include: [
assetIndex,
],
exclude: /(node_modules|bower_components)/,
query: {
cacheDirectory: true,
},
},
{
test: /\.json$/,
loaders: 'json-loader',
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loaders: 'url-loader',
query: {
limit: 10000,
mimetype: 'application/font-woff',
name: `${fontPath}[name].[ext]`,
},
},
{
test: /\.(ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loaders: 'file-loader',
query: {
name: `${fontPath}[name].[ext]`,
},
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
mangle: false
}),
new ExtractTextPlugin({
filename: '../static/css/app.css',
allChunks: true,
})
],
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment