Created
March 5, 2018 20:20
-
-
Save gijun19/b6172e3eb3ad500e95c9e8b51cd93007 to your computer and use it in GitHub Desktop.
Webpack Config Boilerplate
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
/** | |
* webpack.config.js | |
* @author Daniel Park <[email protected]> | |
* Webpack configuration file. | |
*/ | |
// Require necessary modules. | |
const webpack = require('webpack'); | |
const path = require('path'); | |
// Use Webpack plugins. | |
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | |
const HtmlWebpackPlugin = require('html-webpack-plugin'); | |
const CleanWebpackPlugin = require('clean-webpack-plugin'); | |
const extractCss = new ExtractTextPlugin({ filename: './css/[name].css' }); | |
module.exports = { | |
// Declare the absolute path for project root. | |
context: path.resolve(__dirname, 'src'), | |
// Entry point for our application. | |
entry: { | |
app: './app.js', | |
vendor: ['jquery', 'lodash', 'aos'] | |
}, | |
// Output configuration | |
output: { | |
path: path.resolve(__dirname, 'dist'), | |
filename: './js/[name].bundle.js' | |
}, | |
// Plugins for Webpack configuration. | |
plugins: [ | |
// Clean up 'dist' folder on build. | |
new CleanWebpackPlugin(['dist']), | |
new HtmlWebpackPlugin({ | |
template: 'index.html' | |
}), | |
new webpack.optimize.CommonsChunkPlugin({ | |
name: 'vendor' | |
}), | |
extractCss | |
], | |
// Module loader configuration. | |
module: { | |
rules: [ | |
{ | |
test: /\.js$/, | |
include: /src/, | |
exclude: /node_modules/, | |
use: { | |
loader: 'babel-loader', | |
options: { presets: ['env'] } | |
} | |
}, | |
{ | |
test: /\.html$/, | |
use: ['html-loader'] | |
}, | |
{ | |
test: /\.scss$/, | |
use: extractCss.extract({ | |
use: [ | |
{ | |
loader: 'css-loader', | |
options: { | |
sourceMap: true | |
} | |
}, | |
{ | |
loader: 'resolve-url-loader' | |
}, | |
{ | |
loader: 'sass-loader', | |
options: { | |
sourceMap: true | |
} | |
} | |
], | |
fallback: 'style-loader' | |
}) | |
}, | |
{ | |
test: /\.(jpg|png|gif|svg)$/, | |
use: [ | |
{ | |
loader: 'file-loader', | |
options: { | |
name: '[name].[ext]', | |
outputPath: './assets/media/' | |
} | |
} | |
] | |
}, | |
{ | |
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, | |
use: [ | |
{ | |
loader: 'url-loader', | |
options: { | |
name: '[name].[ext]', | |
outputPath: './css/fonts' | |
} | |
} | |
] | |
}, | |
{ | |
test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, | |
use: [ | |
{ | |
loader: 'file-loader', | |
options: { | |
name: '[name].[ext]', | |
outputPath: './css/fonts' | |
} | |
} | |
] | |
} | |
] | |
}, | |
// Webpack Dev Server configuration. | |
devServer: { | |
// Specify where static files are served. | |
contentBase: path.resolve(__dirname, "./dist"), | |
watchContentBase: true, | |
compress: true, | |
port: 1234, | |
stats: 'errors-only' | |
}, | |
// Other configuration. | |
devtool: 'inline-source-map' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment