forked from Opentrons/opentrons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
92 lines (78 loc) · 2.43 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
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
'use strict'
const path = require('path')
const webpack = require('webpack')
const merge = require('webpack-merge')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FaviconsWebpackPlugin = require('favicons-webpack-plugin')
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin')
const { DEV_MODE, baseConfig } = require('@opentrons/webpack-config')
const { productName: title, description, author } = require('./package.json')
const PROTOCOL_DESIGNER_ENV_VAR_PREFIX = 'OT_PD_'
// TODO: BC: 2018-02-21 remove hardcoded semver version and replace
// with string from package.json version inserted at build time
// Also remove all OT_PD_VERSION env vars, the version should always
// be gleaned from the package.json
const OT_PD_VERSION = '5.2.3'
const OT_PD_BUILD_DATE = new Date().toUTCString()
const JS_ENTRY = path.join(__dirname, 'src/index.js')
const HTML_ENTRY = path.join(__dirname, 'src/index.hbs')
const ERROR_HTML = path.join(__dirname, 'src/error.html')
const passThruEnvVars = Object.keys(process.env)
.filter(v => v.startsWith(PROTOCOL_DESIGNER_ENV_VAR_PREFIX))
.concat(['NODE_ENV', 'CYPRESS'])
const envVarsWithDefaults = {
OT_PD_VERSION,
OT_PD_BUILD_DATE,
}
const envVars = passThruEnvVars.reduce(
(acc, envVar) => ({ [envVar]: '', ...acc }),
{ ...envVarsWithDefaults }
)
const testAliases =
process.env.CYPRESS === '1'
? {
'file-saver': path.resolve(__dirname, 'cypress/mocks/file-saver.js'),
}
: {}
console.log(`PD version: ${OT_PD_VERSION || 'UNKNOWN!'}`)
module.exports = merge(baseConfig, {
entry: [JS_ENTRY],
output: {
path: path.join(__dirname, 'dist'),
publicPath: DEV_MODE ? '' : './',
},
plugins: [
new webpack.EnvironmentPlugin(envVars),
new FaviconsWebpackPlugin({
logo: './src/images/favicon-logo.png',
prefix: 'icons-[hash]/',
inject: true,
background: '#fff',
icons: {
android: false,
appleIcon: false,
appleStartup: false,
coast: false,
favicons: true,
firefox: false,
windows: false,
yandex: false,
},
}),
new HtmlWebpackPlugin({
title,
description,
author,
template: HTML_ENTRY,
}),
new HtmlWebpackPlugin({
filename: 'error.html',
inject: false,
template: ERROR_HTML,
}),
new ScriptExtHtmlWebpackPlugin({ defaultAttribute: 'defer' }),
],
resolve: {
alias: testAliases,
},
})