This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack-extension.config.js
154 lines (143 loc) · 4.49 KB
/
webpack-extension.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
const path = require('path');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { babel } = require('./package.json');
const isProd = process.env.NODE_ENV === 'production';
module.exports = {
target: 'web',
mode: isProd ? 'production' : 'development',
entry: {
background: './src/background.js',
'content-script': './src/content-script.js',
popup: './src/popup.js'
},
output: {
filename: `[name].js`,
path: path.resolve(__dirname, 'extension/')
},
devtool: isProd ? undefined : 'cheap-module-source-map', // !! eval is not allowed for web extensions
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: babel.presets,
plugins: [
'@babel/plugin-transform-async-to-generator',
'@babel/plugin-proposal-class-properties'
]
}
}
],
exclude: isProd ? /node_modules/ : undefined,
include: [path.resolve(__dirname, 'src')]
},
{
test: /\.css$/,
sideEffects: true,
use: [
{
loader: MiniCssExtractPlugin.loader,
options: {
hmr: false,
publicPath: path.resolve(__dirname, 'extension/')
}
},
{
loader: 'css-loader',
options: {
importLoaders: 1,
sourceMap: true
}
},
{
loader: 'postcss-loader',
options: {
ident: 'postcss',
plugins: function(loader) {
return [
require('postcss-import')(),
require('postcss-url')({
filter: asset => {
return /^.*\.(svg|png|css|jpeg)$/.test(
asset.relativePath
);
}
}),
require('postcss-replace')({
data: {
EXTENSION_ROOT:
process.env.EXTENSION_BROwSER_ENV === 'firefox'
? 'moz-extension'
: 'chrome-extension'
}
}),
require('postcss-preset-env')({
/* see: https://github.com/csstools/postcss-preset-env/issues/32 */
browsers: 'last 2 versions',
stage: 3,
features: {
'nesting-rules': false /* disable css nesting which does not allow nesting of selectors without white spaces between them */,
'custom-media-queries': true
}
}),
require('postcss-nested'), // replace cssnext nesting with this one which allows for sass style nesting
require('postcss-plugin-namespace')('#rpos-ext', {
ignore: [
':root',
'html',
/^body/,
/^\[data-reach/,
/#rpos-ext/
]
})
// require('postcss-scopify')('#rpos-ext')
];
}
}
}
],
include: [path.resolve(__dirname, 'src')]
},
{
test: /\.svg$/,
issuer: {
test: /\.jsx?$/
},
use: ['@svgr/webpack']
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
issuer: {
test: /\.css$/
},
loader: 'url-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(
process.env.NODE_ENV || 'development'
),
'process.env.IS_EXTENSION': true,
'process.env.COOKIE_URL': JSON.stringify(
process.env.NODE_ENV === 'production'
? 'https://outbreaksci.prereview.org' // 'https://rapid-prereview.azurewebsites.net' !! KEEP IN SYNC WITH src/constants
: 'http://127.0.0.1'
),
'process.env.API_URL': JSON.stringify(
process.env.NODE_ENV === 'production'
? 'https://outbreaksci.prereview.org' // 'https://rapid-prereview.azurewebsites.net' !! KEEP IN SYNC WITH src/constants
: 'http://127.0.0.1:3000'
)
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: '[id].css'
})
]
};