forked from CyberAgentHack/web-speed-hackathon-2021
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
90 lines (86 loc) · 2.36 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const MomentLocalesPlugin = require('moment-locales-webpack-plugin');
const webpack = require('webpack');
const SRC_PATH = path.resolve(__dirname, './src');
const PUBLIC_PATH = path.resolve(__dirname, '../public');
const UPLOAD_PATH = path.resolve(__dirname, '../upload');
const DIST_PATH = path.resolve(__dirname, '../dist');
/** @type {import('webpack').Configuration} */
const config = {
devServer: {
historyApiFallback: true,
host: '0.0.0.0',
port: 8080,
proxy: {
'/api': 'http://localhost:3000',
},
static: [PUBLIC_PATH, UPLOAD_PATH],
},
devtool: process.env.NODE_ENV === 'production' ? false : 'inline-source-map',
entry: {
main: [
'core-js',
'regenerator-runtime/runtime',
'jquery-binarytransport',
path.resolve(SRC_PATH, './index.css'),
path.resolve(SRC_PATH, './buildinfo.js'),
path.resolve(SRC_PATH, './index.jsx'),
],
},
mode: process.env.NODE_ENV,
module: {
rules: [
{
exclude: /node_modules/,
test: /\.jsx?$/,
use: [{ loader: 'babel-loader' }],
},
{
test: /\.css$/i,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: 'css-loader', options: { url: false } },
{ loader: 'postcss-loader' },
],
},
],
},
output: {
filename: 'scripts/[name].js',
path: DIST_PATH,
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
AudioContext: ['standardized-audio-context', 'AudioContext'],
Buffer: ['buffer', 'Buffer'],
'window.jQuery': 'jquery',
}),
new webpack.EnvironmentPlugin({
BUILD_DATE: new Date().toISOString(),
// Heroku では SOURCE_VERSION 環境変数から commit hash を参照できます
COMMIT_HASH: process.env.SOURCE_VERSION || '',
NODE_ENV: 'development',
}),
new MiniCssExtractPlugin({
filename: 'styles/[name].css',
}),
new HtmlWebpackPlugin({
inject: false,
template: path.resolve(SRC_PATH, './index.html'),
}),
new MomentLocalesPlugin({
localesToKeep: ['ja'],
}),
],
resolve: {
extensions: ['.js', '.jsx'],
fallback: {
fs: false,
path: false,
},
},
};
module.exports = config;