Skip to content

Commit fdb84c7

Browse files
committedSep 4, 2022
Use webpack --env via docs for future KEYPOST_APP_HOST use
1 parent d583987 commit fdb84c7

File tree

3 files changed

+43
-36
lines changed

3 files changed

+43
-36
lines changed
 

‎.envrc

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export NODE_OPTIONS=--openssl-legacy-provider
2+
export KEYPOST_APP_HOST=localhost:8000

‎package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"webpack-dev-server": "^4.10.1"
1616
},
1717
"scripts": {
18-
"start": "webpack-dev-server --mode development",
19-
"build": "webpack --mode production"
18+
"start": "webpack-dev-server --mode development --env KEYPOST_APP_HOST=$KEYPOST_APP_HOST",
19+
"build": "webpack --mode production --env production --env KEYPOST_APP_HOST=$KEYPOST_APP_HOST"
2020
},
2121
"dependencies": {
2222
"@cloudflare/opaque-ts": "^0.7.5"

‎webpack.config.ts

+40-34
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,46 @@
11
const HtmlWebpackPlugin = require("html-webpack-plugin");
22
const path = require('path');
33

4-
module.exports = {
5-
entry: './src/index.ts',
6-
module: {
7-
rules: [
8-
{
9-
test: /\.ts?$/,
10-
use: 'ts-loader',
11-
exclude: /node_modules/,
12-
}
13-
],
14-
},
15-
resolve: {
16-
extensions: ['.tsx', '.ts', '.js'],
17-
},
18-
output: {
19-
filename: 'bundle.js',
20-
path: path.resolve(__dirname, 'dist'),
21-
},
4+
module.exports = (env: any) => {
5+
// https://webpack.js.org/guides/environment-variables/ Use env.<YOUR VARIABLE> here:
6+
console.log('KEYPOST_APP_HOST: ', env.KEYPOST_APP_HOST);
7+
console.log('production: ', env.production || false);
8+
9+
return {
10+
entry: './src/index.ts',
11+
module: {
12+
rules: [
13+
{
14+
test: /\.ts?$/,
15+
use: 'ts-loader',
16+
exclude: /node_modules/,
17+
}
18+
],
19+
},
20+
resolve: {
21+
extensions: ['.tsx', '.ts', '.js'],
22+
},
23+
output: {
24+
filename: 'bundle.js',
25+
path: path.resolve(__dirname, 'dist'),
26+
},
2227

23-
plugins: [
24-
// https://github.com/jantimon/html-webpack-plugin#options
25-
new HtmlWebpackPlugin({
26-
title: 'tutorial',
27-
template: 'src/custom.html',
28-
filename: 'custom.html'}),
29-
new HtmlWebpackPlugin({
30-
title: 'Keypost Home',
31-
template: 'src/index.html',
32-
filename: 'index.html'})
33-
],
28+
plugins: [
29+
// https://github.com/jantimon/html-webpack-plugin#options
30+
new HtmlWebpackPlugin({
31+
title: 'tutorial',
32+
template: 'src/custom.html',
33+
filename: 'custom.html'}),
34+
new HtmlWebpackPlugin({
35+
title: 'Keypost Home',
36+
template: 'src/index.html',
37+
filename: 'index.html'})
38+
],
3439

35-
devServer: {
36-
static: path.join(__dirname, "dist"),
37-
compress: true,
38-
port: 4000,
39-
},
40+
devServer: {
41+
static: path.join(__dirname, "dist"),
42+
compress: true,
43+
port: 4000,
44+
},
45+
};
4046
};

0 commit comments

Comments
 (0)