-
Notifications
You must be signed in to change notification settings - Fork 1k
/
webpack.common.js
89 lines (80 loc) · 2.15 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
'use strict'
const webpack = require('webpack')
const path = require('path')
const buildPath = path.resolve(__dirname, 'dist')
const args = require('yargs').argv
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const env = args.envFile
if (env) {
// Load env file
require('dotenv').config({ path: env })
}
const common = ['./src/common.js']
const ASSET_PATH = process.env.ASSET_PATH || '/'
const plugins = [
new MiniCssExtractPlugin({ filename: '[name].[contenthash].css' }),
new HtmlWebpackPlugin({
template: './src/index.html',
chunks: ['main'],
inject: 'body',
}),
new webpack.DefinePlugin({
'process.env.CLIENT_ID': JSON.stringify(process.env.CLIENT_ID),
'process.env.API_KEY': JSON.stringify(process.env.API_KEY),
'process.env.ENABLE_GOOGLE_AUTH': JSON.stringify(process.env.ENABLE_GOOGLE_AUTH),
'process.env.GTM_ID': JSON.stringify(process.env.GTM_ID),
'process.env.RINGS': JSON.stringify(process.env.RINGS),
'process.env.QUADRANTS': JSON.stringify(process.env.QUADRANTS),
'process.env.ADOBE_LAUNCH_SCRIPT_URL': JSON.stringify(process.env.ADOBE_LAUNCH_SCRIPT_URL),
}),
]
module.exports = {
context: __dirname,
entry: {
common: common,
},
output: {
path: buildPath,
publicPath: ASSET_PATH,
filename: '[name].[contenthash].js',
assetModuleFilename: 'images/[name][ext]',
},
resolve: {
extensions: ['.js', '.ts'],
fallback: {
fs: false,
},
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
],
},
{
test: /\.(eot|otf|ttf|woff|woff2)$/,
type: 'asset/resource',
},
{
test: /\.(png|jpg|jpeg|gif|ico|svg)$/,
exclude: /node_modules/,
type: 'asset/resource',
},
{
test: require.resolve('jquery'),
loader: 'expose-loader',
options: { exposes: ['$', 'jQuery'] },
},
],
},
plugins: plugins,
}