This repository has been archived by the owner on Sep 4, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
123 lines (114 loc) · 3.35 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
115
116
117
118
119
120
121
122
123
'use strict';
/* eslint no-const: 0 */
const _curry = require('lodash/curry');
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const StaticSiteGeneratorPlugin = require('static-site-generator-webpack-plugin');
const WebpackRobots = require('@tanepiper/webpack-robotstxt');
const SitemapPlugin = require('sitemap-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const environment = process.env.NODE_ENV || 'development';
const development = environment === 'development';
const paths = [
'/',
'/privacy',
'/tos',
];
const lIN = development ? '[name]__[local]' : '[hash:base64]';
const outputPath = path.join(__dirname, 'build');
const makePlugin = _curry((state, name) => `{${name}:${state}}`);
const truePlugins = [ 'removeTitle', 'removeDesc', 'removeViewBox', 'removeDimensions' ].map(makePlugin('true'));
const falsePlugins = [].map(makePlugin('false'));
const pluginList = [].concat(truePlugins, falsePlugins).join(',');
const svgoOptions = `svgo:{plugins:[${pluginList}]}`;
const domain = 'https://tryvoo.com';
const sitemapName = 'sitemap.xml';
module.exports = {
entry: {
main: './src/index.js',
landing: './src/static/landing.js',
legal: './src/static/legal.js',
},
output: {
path: outputPath,
filename: '[name].[chunkhash].js',
libraryTarget: 'umd',
publicPath: '/',
},
resolve: {
modulesDirectories: [
'src',
'node_modules',
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(environment),
'__API_URL__': JSON.stringify(development ? '/api' : 'https://api.letsroundup.com'),
'__DEV__': development,
}),
new ExtractTextPlugin('main.[contenthash].css'),
new webpack.NoErrorsPlugin(),
new StaticSiteGeneratorPlugin('main', paths, {}),
new SitemapPlugin(domain, paths, sitemapName),
new WebpackRobots({ sitemap: `${domain}/${sitemapName}` }),
new CopyWebpackPlugin([ {
context: path.join(__dirname, 'src/thirdparties/js'),
from: '**/*',
} ]),
],
module: {
loaders: [
{ test: /\.js$/, exclude: /node_modules/, loader: 'babel' },
{
test: /.(css)$/,
loader: ExtractTextPlugin.extract(
'style',
'css'
),
include: /thirdparties/,
},
{
test: /\.(s?css)$/,
loader: ExtractTextPlugin.extract(
'style',
'css?modules&localIdentName=' + lIN + '!autoprefixer?browsers=last 2 version!sass'
),
exclude: /thirdparties/,
},
{
test: /\.(svg)/,
loaders: [
`file-loader`,
`image-webpack?{${svgoOptions}}`,
],
},
{
test: /\.(png|jpg|jpeg|gif)/,
loader: `file-loader`,
},
{ test: /\.(mp4)/, loader: 'file-loader' },
{ test: /CNAME|LICENSE/, loader: 'file-loader?name=[name]' },
{ test: /\.md/, loader: 'file-loader?name=[name].[ext]' },
],
},
devServer: {
outputPath,
host: '0.0.0.0',
proxy: {
'/api/*': {
'target': {
'host': 'localhost',
'protocol': 'http:',
'port': 3001,
},
rewrite: (req) => {
req.url = req.url.replace(/^\/api/, '');
},
changeOrigin: true,
secure: false,
},
},
},
};