2019-04-08 08:38:15 +00:00
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
|
2019-12-06 19:59:14 +00:00
|
|
|
const { CleanWebpackPlugin } = require('clean-webpack-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-12-06 19:59:14 +00:00
|
|
|
console.log(`Using mode ${isProduction ? 'PRODUCTION' : 'DEVELOPMENT'}`)
|
|
|
|
|
2019-04-19 20:56:15 +00:00
|
|
|
return {
|
|
|
|
context: path.resolve(__dirname, 'src'),
|
2019-04-08 08:38:15 +00:00
|
|
|
|
2019-12-06 19:59:14 +00:00
|
|
|
devServer: {
|
|
|
|
contentBase: path.resolve(__dirname, 'dist'),
|
|
|
|
port: 3100,
|
|
|
|
},
|
|
|
|
|
|
|
|
devtool: 'inline-source-map',
|
|
|
|
|
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-12-06 19:59:14 +00:00
|
|
|
plugins: Array.prototype.concat([
|
|
|
|
new CleanWebpackPlugin(),
|
|
|
|
], isProduction
|
|
|
|
? []
|
|
|
|
: [
|
|
|
|
new BrowserSyncPlugin({
|
|
|
|
host: 'localhost',
|
|
|
|
open: false,
|
|
|
|
proxy: 'http://localhost:3100/',
|
|
|
|
}),
|
|
|
|
])
|
2019-04-19 20:56:15 +00:00
|
|
|
}
|
2019-04-08 08:38:15 +00:00
|
|
|
}
|