Skip to content

Instantly share code, notes, and snippets.

@TareqElMasriDev
Created February 2, 2017 09:51
Show Gist options
  • Save TareqElMasriDev/f66f9e966109e2d425842c654b4221fc to your computer and use it in GitHub Desktop.
Save TareqElMasriDev/f66f9e966109e2d425842c654b4221fc to your computer and use it in GitHub Desktop.
Webpack Configurations
const path = require('path')
const webpack = require('webpack')
const autoprefixer = require('autoprefixer')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
const ModernizrPlugin = require('modernizr-webpack-plugin')
const production = process.argv.indexOf("--production") > -1
module.exports = {
devtool: 'source-map',
resolve: {
root: path.join(__dirname, '../'),
extensions: [
"",
".js",
".json",
".scss"
]
},
entry: {
'scripts/bundle.js': './app/index.js',
'styles/style.css': './app/index.scss',
},
alias: {
jquery: "jquery/src/jquery"
},
output: {
path: path.resolve(__dirname, '../public'),
filename: "[name]",
publicPath: "/dist",
},
plugins: [
// new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(),
new ExtractTextPlugin('[name]'),
// new ModernizrPlugin(require('../modernizr.json')),
new BrowserSyncPlugin({
// browse to http://localhost:3000/ during development,
// ./public directory is being served
host: "localhost",
port: 9000,
open: false,
files: "./**/*",
reloadOnRestart: true,
proxy: {
target: "http://localhost:3000",
ws: true
},
}),
new CleanWebpackPlugin(['scripts', 'styles', '.tmp'], {
root: path.resolve(__dirname, '../public'),
verbose: true
}),
new webpack.DefinePlugin({
_: 'lodash',
__PROD__: production,
$: "jquery",
jQuery: "jquery"
}),
].concat(
production ? [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
}),
] : []
),
module: {
preLoaders: [{
test: /\.json$/,
exclude: /node_modules/,
loader: 'json'
}],
loaders: [{
test: /\.js$/,
loader: 'babel',
query: {
presets: ['es2015', 'stage-0']
}
}, {
test: /\.(css|sass|scss)$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap!sass?sourceMap')
}, {
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
loader: 'file-loader?name=fonts/[name].[ext]'
}, {
test: /\.(png|jpg)$/,
loader: 'url?limit=25000'
}]
},
sassLoader: {
includePaths: [
require('node-bourbon').includePaths,
require('bourbon-neat').includePaths,
]
},
postcss: [
autoprefixer({
browsers: ['last 2 versions']
})
],
cssnext: {
sourcemap: !production,
compress: production,
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment