-
Notifications
You must be signed in to change notification settings - Fork 11
/
webpack.common.js
115 lines (101 loc) · 3.67 KB
/
webpack.common.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
/* eslint-disable no-var, strict, prefer-arrow-callback */
'use strict';
const path = require('path');
const webpack = require('webpack');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
const packageJson = require('./package.json');
const vendorDependencies = Object.keys(packageJson['dependencies']);
const dotenv = require('dotenv');
const loadEnv = envPath => {
try {
dotenv.config({ path: envPath });
} catch (err) {
// only ignore error if file is not found
if (err.toString().indexOf('ENOENT') < 0) {
throw err;
}
}
}
// Contrary to what you'd expect, the first env loaded is the one whose values are kept
loadEnv(path.join(__dirname, './.env.local'));
loadEnv(path.join(__dirname, './.env'));
module.exports = {
entry: {
main: ['babel-polyfill', "./src/eterna/index.ts"],
vendor: vendorDependencies
},
output: {
filename: '[name].[chunkhash].js',
chunkFilename: 'bundles/[chunkhash].js'
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"],
alias: {
assets: path.resolve(__dirname, 'assets/'),
signals: path.resolve(__dirname, 'src/signals'),
flashbang: path.resolve(__dirname, 'src/flashbang'),
eterna: path.resolve(__dirname, 'src/eterna'),
}
},
module: {
rules: [
{
// Include ts, tsx, and js files.
test: /\.(tsx?)|(js)$/,
exclude: /node_modules/,
loader: 'babel-loader',
options: {
cacheDirectory: true
}
},
{
test: /\.(png|jpg|gif|mp3|ttf)$/,
use: [
{
loader: 'file-loader',
options: {name: 'assets/[name].[hash].[ext]'},
}
]
},
{
test: /\.css$/,
use: ['style-loader', 'css-loader']
}
],
},
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
externals: {
// "react": "React",
// "react-dom": "ReactDOM"
},
// 5/15/18 - Cargo-culting this line in to fix 'Module not found: Error: Can't resolve 'fs''
// https://github.com/webpack-contrib/css-loader/issues/447
node: {
fs: "empty"
},
plugins: [
// Caching plugin for faster builds
// https://github.com/mzgoddard/hard-source-webpack-plugin
new HardSourceWebpackPlugin({
environmentHash: {
root: process.cwd(),
directories: [],
files: ['package-lock.json', 'yarn.lock', '.env', '.env.local']
}
}),
new webpack.EnvironmentPlugin(Object.keys(process.env)),
// Generate an index.html that includes our webpack bundles
new HtmlWebpackPlugin({template: 'src/index.html.tmpl', inject: false}),
// Generate a manifest.json file containing our entry point file names:
// https://github.com/danethurber/webpack-manifest-plugin#hooks-options
new ManifestPlugin({
filter: (item) => item.isInitial
}),
]
};