This repository has been archived by the owner on Jul 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
114 lines (109 loc) · 2.31 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const autoprefixer = require('autoprefixer');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ENV = process.env.NODE_ENV || 'development';
const babelrc = require('./babel');
const PATHS = {
src: path.resolve(__dirname, 'src'),
public: path.resolve(__dirname, 'public'),
};
const plugins = [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(ENV),
}),
new ExtractTextPlugin({
filename: '[name].css',
allChunks: false,
disable: ENV !== 'production',
}),
];
const prodPlugins = [
...plugins,
new CopyWebpackPlugin([
{ from: 'img', to: 'img' },
{ from: 'meta' },
{ from: 'static' },
{ from: 'index.html' },
{ from: 'json/resume.json' },
], {
ignore: ['*.psd'],
copyUnmodified: true,
}),
];
module.exports = {
context: PATHS.src,
entry: {
src: './index.js',
vendor: ['react', 'moment', 'lodash', 'firebase'],
},
output: {
path: PATHS.public,
filename: '[name].js',
},
resolve: {
extensions: ['.js', '.jsx', '.ts', '.scss', '.json'],
modules: [path.resolve('node_modules'), 'node_modules'],
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: babelrc(ENV),
},
},
{
test: /\.(jpe?g|png|gif|webm)$/,
use: 'file-loader',
},
{
test: /\.(css|scss|sass)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: false,
importLoaders: true,
},
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
sourceMap: 'inline',
plugins: () => {
return [autoprefixer({ browsers: ['> 1%', 'IE >= 10'] })];
},
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
includePaths: [PATHS.src],
},
},
],
}),
},
{
test: /\.svg/,
use: 'svg-url-loader',
},
],
},
plugins: ENV === 'production' ? prodPlugins : plugins,
devtool: ENV === 'production' ? 'source-map' : 'eval',
devServer: {
port: 3000,
host: 'localhost',
historyApiFallback: true,
},
};