forked from taniarascia/takenote
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.common.js
97 lines (93 loc) Β· 2.6 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
const path = require('path')
const dotenv = require('dotenv')
const webpack = require('webpack')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
/**
* Obtain client id for OAuth link in React
*
* If in development mode or local production mode, search the .env file for
* client id. If using Docker, pass a build arg.
*/
const getEnvFromDotEnvFile = dotenv.config()
let envKeys
if (getEnvFromDotEnvFile.error) {
console.log('Getting environment variables from build args for production') // eslint-disable-line
envKeys = {
'process.env.CLIENT_ID': JSON.stringify(process.env.CLIENT_ID),
'process.env.DEMO': JSON.stringify(process.env.DEMO),
'process.env.NODE_ENV': JSON.stringify('production'),
}
} else {
envKeys = {
'process.env.CLIENT_ID': JSON.stringify(getEnvFromDotEnvFile.parsed['CLIENT_ID']),
'process.env.DEMO': JSON.stringify(getEnvFromDotEnvFile.parsed['DEMO']),
}
}
module.exports = {
entry: ['./src/client/index.tsx'],
output: {
path: path.resolve(__dirname, '../dist'),
filename: '[name].[fullhash].bundle.js',
publicPath: '/',
},
module: {
rules: [
/**
* TypeScript (.ts/.tsx files)
*
* The TypeScript loader will compile all .ts/.tsx files to .js. Babel is
* not necessary here since TypeScript is taking care of all transpiling.
*/
{
test: /\.ts(x?)$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
// Fonts
{
test: /\.(woff(2)?|eot|ttf|otf)$/,
type: 'asset/inline',
},
// Markdown
{
test: /\.md$/,
type: 'asset/source',
},
// Images
{
test: /\.(?:ico|gif|png|jpg|jpeg|webp|svg)$/i,
type: 'asset/resource',
},
],
},
resolve: {
// Resolve in this order
extensions: ['*', '.js', '.jsx', '.ts', '.tsx', '.md'],
// Allow `@/` to map to `src/client/`
alias: {
'@': path.resolve(__dirname, '../src/client'),
'@resources': path.resolve(__dirname, '../src/resources'),
stream: 'stream-browserify',
path: 'path-browserify',
},
},
plugins: [
// Get environment variables in React
new webpack.DefinePlugin(envKeys),
new CleanWebpackPlugin(),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, '../public'),
globOptions: {
ignore: ['*.DS_Store', 'favicon.ico', 'template.html'],
},
},
],
}),
new webpack.ProvidePlugin({
process: 'process/browser',
}),
],
}