-
Notifications
You must be signed in to change notification settings - Fork 729
/
webpack.config.build.js
154 lines (151 loc) · 3.87 KB
/
webpack.config.build.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 webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const cssnano = require('cssnano')
const path = require('path')
const config = require('./webpack.config')
const HappyPack = require('happypack')
const os = require('os')
const fs = require('fs')
const UglifyJSParallelPlugin = require('webpack-uglify-parallel')
const { renderPlaygroundPage } = require('graphql-playground-html')
const appEntrypoint = 'src/renderer/index.html'
// Create the playground entry point if it doesn't exist
if (!fs.existsSync(appEntrypoint)) {
fs.writeFileSync(appEntrypoint, renderPlaygroundPage({ env: 'react' }))
}
module.exports = {
devtool: 'source-map',
mode: 'production',
target: 'electron-renderer',
entry: {
app: ['./src/renderer'],
},
output: {
path: __dirname + '/dist',
filename: '[name].[hash].js',
sourceMapFilename: '[file].map',
publicPath: './',
},
node: {
__dirname: false,
__filename: false,
},
module: {
rules: [
{
enforce: 'pre',
test: /\.ts(x?)$/,
loader: 'tslint-loader',
exclude: /node_modules/,
},
{
test: /\.css$/,
loader: 'style-loader!css-loader',
},
{
test: /\.scss$/,
loader:
'style-loader!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]!postcss-loader!sass-loader',
},
{
test: /\.ts(x?)$/,
include: __dirname + '/src',
use: [
{
loader: 'happypack/loader?id=babel',
},
{
loader: 'happypack/loader?id=ts',
},
],
},
{
test: /\.js$/,
loader: 'happypack/loader?id=babel',
include: __dirname + '/src',
},
{
test: /\.mp3$/,
loader: 'file-loader',
},
{
test: /icons\/.*\.svg$/,
loader:
'raw-loader!svgo-loader?{"plugins":[{"removeStyleElement":true}]}',
},
{
test: /graphics\/.*\.svg$/,
loader: 'file-loader',
},
{
test: /.*\.(png|gif)$/,
loader: 'file-loader',
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
},
__EXAMPLE_ADDR__: '"https://dynamic-resources.graph.cool"',
}),
new HtmlWebpackPlugin({
favicon: 'static/favicon.png',
template: appEntrypoint,
}),
new webpack.optimize.OccurrenceOrderPlugin(),
/* new UglifyJSParallelPlugin({
workers: os.cpus().length,
compress: {
unused: true,
dead_code: true,
warnings: false,
},
sourceMap: false,
mangle: false,
}), */
// https://github.com/graphql/graphql-language-service/issues/111
new webpack.ContextReplacementPlugin(
/graphql-language-service-interface[\/\\]dist/,
/\.js$/,
),
new webpack.NormalModuleReplacementPlugin(/\/iconv-loader$/, 'node-noop'),
// new webpack.optimize.CommonsChunkPlugin('vendor'),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.LoaderOptionsPlugin({
options: {
postcss: [
cssnano({
autoprefixer: {
add: true,
remove: true,
browsers: ['last 2 versions'],
},
discardComments: {
removeAll: true,
},
safe: true,
}),
],
svgo: {
plugins: [{ removeStyleElement: true }],
},
},
}),
new HappyPack({
id: 'ts',
threads: 2,
loaders: ['ts-loader?' + JSON.stringify({ happyPackMode: true })],
}),
new HappyPack({
id: 'babel',
threads: 2,
loaders: ['babel-loader'],
}),
],
resolve: {
modules: [path.resolve('./src'), 'node_modules'],
extensions: ['.mjs', '.js', '.ts', '.tsx'],
},
}