Homepage/webpack.config.js

81 lines
2.5 KiB
JavaScript
Raw Normal View History

2019-04-08 08:38:15 +00:00
const path = require('path')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
2019-04-19 20:56:15 +00:00
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
2019-04-08 08:38:15 +00:00
2019-04-19 20:56:15 +00:00
module.exports = (env, argv) => {
const isProduction = argv.mode === 'production'
2019-04-08 08:38:15 +00:00
2019-04-19 20:56:15 +00:00
return {
context: path.resolve(__dirname, 'src'),
2019-04-08 08:38:15 +00:00
2019-04-19 20:56:15 +00:00
mode: isProduction ? 'production' : 'development',
entry: {
index: './index.js',
},
module: {
rules: [
{
test: /\.(jpg|png|svg)$/,
include: [
path.resolve(__dirname, 'src')
],
use: [
isProduction ?
'file-loader?name=[path][name].[contenthash:8].[ext]' :
'file-loader?name=[path][name].[ext]'
],
},
{
test: /\.(eot|svg|ttf|woff2?)$/,
include: [
path.resolve(__dirname, 'node_modules')
],
use: [
isProduction ?
'file-loader?name=assets/webfonts/[name].[contenthash:8].[ext]' :
'file-loader?name=assets/webfonts/[name].[ext]'
],
},
{
test: /\.(html)$/,
use: [
'file-loader?name=[name].[ext]',
'extract-loader',
'html-loader?interpolate',
],
2019-04-08 08:38:15 +00:00
},
2019-04-19 20:56:15 +00:00
{
test: /\.(c|sa|sc)ss$/,
use: [
isProduction ?
'file-loader?name=[name].[contenthash:8].css' :
'file-loader?name=[name].css',
'extract-loader',
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
2019-04-08 08:38:15 +00:00
},
2019-04-19 20:56:15 +00:00
'sass-loader',
],
},
],
},
2019-04-08 08:38:15 +00:00
2019-04-19 20:56:15 +00:00
output: {
filename: '[name].[contenthash:8].js',
path: path.resolve(__dirname, 'dist'),
},
2019-04-08 08:38:15 +00:00
2019-04-19 20:56:15 +00:00
plugins: [
new BrowserSyncPlugin({
host: 'localhost',
server: { baseDir: ['dist'] },
})
],
}
2019-04-08 08:38:15 +00:00
}