forked from dis-moi/extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.profiles.config.js
114 lines (109 loc) · 3 KB
/
webpack.profiles.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
const path = require('path');
const { DefinePlugin } = require('webpack');
const loadEnv = require('./loadEnv');
const defaultWebpack = require('./webpack.config');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const basePlugins = require('./webpack/config.plugins.base');
const R = require('ramda');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const LodashModuleReplacementPlugin = require('lodash-webpack-plugin');
const requiredEnvVarNames = [
'SENTRY_DSN',
'SENTRY_ENABLED',
'NODE_ENV',
'BACKEND_ORIGIN',
'REFRESH_CONTRIBUTORS_INTERVAL',
'CHROME_EXTENSION_ID',
'FIREFOX_EXTENSION_ID',
'PROFILES_ORIGIN',
'POPULAR_CONTRIBUTORS_IDS'
];
const formatEnvVar = value => `"${value}"`;
loadEnv({ path: path.resolve(__dirname) });
module.exports = function webpack(env = {}, argv = {}) {
env = {
PLATFORM: 'chromium',
...process.env,
...env
};
const defaultWebpackConfig = defaultWebpack(env, argv);
return {
...defaultWebpackConfig,
module: {
rules: [
{
oneOf: [
{
test: /\.(png|jpe?g|gif)$/i,
include: path.resolve(__dirname, 'src/'),
loader: 'file-loader',
options: {
publicPath: env.PROFILES_ASSETS_PATH,
name: '[path][name].[ext]',
context: 'src/assets'
}
},
...defaultWebpackConfig.module.rules[0].oneOf
]
}
]
},
entry: [
'core-js/stable',
'regenerator-runtime/runtime',
path.join(path.resolve(__dirname, 'src'), './app/profiles/')
],
devServer: {
historyApiFallback: true,
stats: 'minimal',
contentBase: defaultWebpackConfig.output.path
},
output: {
...defaultWebpackConfig.output,
filename: 'js/profiles.bundle.js'
},
plugins: [
...basePlugins(env, argv),
new HtmlWebpackPlugin({
template: './views/profiles.pug',
filename: 'index.html',
inject: false
}),
new DefinePlugin({
'process.env': R.pipe(
R.pick(requiredEnvVarNames),
R.map(formatEnvVar)
)(env)
}),
new CopyWebpackPlugin(
[
{
from: 'src/assets',
to: defaultWebpackConfig.output.path
},
{
from: 'node_modules/typeface-lato/files/',
to: path.join(defaultWebpackConfig.output.path, 'fonts/')
},
{
from: 'node_modules/typeface-sedgwick-ave/files/',
to: path.join(defaultWebpackConfig.output.path, 'fonts/')
},
{
from: 'test/integration',
to: path.join(
defaultWebpackConfig.output.path,
'test',
'integration'
)
},
{
from: 'etc/profiles/public',
to: defaultWebpackConfig.output.path
}
].filter(Boolean)
),
new LodashModuleReplacementPlugin()
]
};
};