-
Notifications
You must be signed in to change notification settings - Fork 15
/
webpack.config.js
52 lines (51 loc) · 1.21 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
const path = require('path')
const Dotenv = require('dotenv-webpack')
const GasPlugin = require('gas-webpack-plugin')
const webpack = require('webpack')
const fs = require('fs')
const dotenv = require('dotenv')
const getWebPagetestCode = () => {
const result = dotenv.config()
if (result.error) {
throw result.error
}
const WEBPAGETEST_OPTIONS_SCRIPT_PATH = result.parsed.WEBPAGETEST_OPTIONS_SCRIPT_PATH
if (!WEBPAGETEST_OPTIONS_SCRIPT_PATH) {
return
}
const SCRIPT_FILE_PATH = path.resolve(__dirname, WEBPAGETEST_OPTIONS_SCRIPT_PATH)
console.log(SCRIPT_FILE_PATH)
if (!fs.existsSync(SCRIPT_FILE_PATH)) {
return
}
return fs.readFileSync(SCRIPT_FILE_PATH, 'utf-8')
}
module.exports = {
mode: 'none',
entry: {
'gas-webpagetest': './src/index.ts',
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
},
module: {
rules: [
{
test: /\.ts$/,
use: 'ts-loader',
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
devtool: false,
plugins: [
new Dotenv(),
new webpack.DefinePlugin({
'process.env.WEBPAGETEST_OPTIONS_SCRIPT_CODE': JSON.stringify(getWebPagetestCode()),
}),
new GasPlugin(),
],
}