106 lines
2.5 KiB
JavaScript
106 lines
2.5 KiB
JavaScript
const HtmlWebPackPlugin = require('html-webpack-plugin')
|
|
const CopyWebpackPlugin = require('copy-webpack-plugin')
|
|
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
|
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
|
|
const dotenv = require('dotenv')
|
|
const webpack = require('webpack')
|
|
var path = require('path')
|
|
|
|
module.exports = () => {
|
|
let envKeys = {}
|
|
if (process.env.VERCEL_ENV === 'production') {
|
|
envKeys = { API_KEY: process.env.API_KEY }
|
|
} else {
|
|
// call dotenv and it will return an Object with a parsed key
|
|
const env = dotenv.config().parsed
|
|
// reduce env variables to an oject
|
|
envKeys = Object.keys(env).reduce((prev, next) => {
|
|
prev[`process.env.${next}`] = JSON.stringify(env[next])
|
|
return prev
|
|
}, {})
|
|
}
|
|
|
|
return {
|
|
entry: './src/index.js',
|
|
output: {
|
|
path: path.resolve(__dirname, 'dist'),
|
|
filename: 'bundle.js',
|
|
publicPath: '/',
|
|
},
|
|
module: {
|
|
rules: [
|
|
{
|
|
test: /\.js$/,
|
|
exclude: /node_modules/,
|
|
use: {
|
|
loader: 'babel-loader',
|
|
},
|
|
},
|
|
{
|
|
test: /\.svg$/,
|
|
exclude: /node_modules/,
|
|
use: {
|
|
loader: 'svg-react-loader',
|
|
},
|
|
},
|
|
{
|
|
test: /\.css$/,
|
|
include: /node_modules/,
|
|
use: ['style-loader', 'css-loader'],
|
|
},
|
|
{
|
|
test: /\.scss$/,
|
|
use: [
|
|
{
|
|
loader: MiniCssExtractPlugin.loader,
|
|
options: {
|
|
publicPath: '../',
|
|
},
|
|
},
|
|
'css-loader',
|
|
'sass-loader',
|
|
],
|
|
},
|
|
{
|
|
test: /\.(gif|png|jpe?g)$/i,
|
|
use: [
|
|
'file-loader',
|
|
{
|
|
loader: 'image-webpack-loader',
|
|
options: {
|
|
bypassOnDebug: true, // webpack@1.x
|
|
disable: true, // webpack@2.x and newer
|
|
},
|
|
},
|
|
],
|
|
},
|
|
],
|
|
},
|
|
devServer: {
|
|
historyApiFallback: true,
|
|
},
|
|
node: {
|
|
global: true,
|
|
},
|
|
plugins: [
|
|
new webpack.DefinePlugin(envKeys),
|
|
new HtmlWebPackPlugin({
|
|
template: './src/index.html',
|
|
filename: './index.html',
|
|
}),
|
|
new CopyWebpackPlugin({
|
|
patterns: [
|
|
{
|
|
from: 'src/static/images',
|
|
to: 'static/images',
|
|
},
|
|
],
|
|
}),
|
|
new MiniCssExtractPlugin({
|
|
filename: 'main.css',
|
|
}),
|
|
new CleanWebpackPlugin(),
|
|
],
|
|
}
|
|
}
|