forked from seanmiller802/BrowserTime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
87 lines (84 loc) · 2.47 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* eslint-disable prefer-template */
const webpack = require('webpack');
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
require('dotenv').config();
const fileExtensions = ['.jpg', '.jpeg', '.png', '.gif', 'eot', 'otf', 'svg', 'ttf', 'woff', 'woff2'];
const config = {
mode: process.env.NODE_ENV || 'development',
devtool: process.env.NODE_ENV === 'development' ? 'cheap-module-source-map' : false,
entry: {
history: './src/index.js',
},
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'build'),
},
resolve: {
extensions: fileExtensions.concat(['.jsx', '.js', '.css']),
},
performance: {
hints: process.env.NODE_ENV === 'development' ? 'warning' : false,
},
plugins: [
// clean build folder
new CleanWebpackPlugin({
cleanStaleWebpackAssets: !process.env.NODE_ENV === 'development',
}),
new webpack.EnvironmentPlugin(['NODE_ENV']),
// generate the html file where we serve our webpack bundle
new HtmlWebpackPlugin({
meta: {
charset: 'utf-8',
viewport: 'width=device-width, initial-scale=1, shrink-to-fit=no',
},
filename: 'history.html',
template: path.join(__dirname, 'src', 'templates', 'history.html'),
}),
// copy manifest and icons to build the folder
new CopyWebpackPlugin([
{
from: 'src/manifest.json',
transform: (content) => Buffer.from(JSON.stringify({
description: process.env.npm_package_description,
version: process.env.npm_package_version,
...JSON.parse(content.toString()),
})),
},
{
from: 'src/icons',
to: 'icons',
},
]),
new MomentLocalesPlugin({
localesToKeep: ['es-us', 'en'],
}),
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader'],
},
{
test: /\.html$/,
loader: 'html-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: new RegExp('.(' + fileExtensions.join('|') + ')$'),
loader: 'file-loader?name=[name].[ext]',
exclude: /node_modules/,
},
],
},
};
module.exports = config;