Repository navigation
Expand file tree
/
Copy pathwebpack.config.js
More file actions
77 lines (74 loc) · 2.06 KB
/
Copy pathwebpack.config.js
File metadata and controls
77 lines (74 loc) · 2.06 KB
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
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');
const IS_DEV = process.env.NODE_ENV !== 'production';
const hasBabelRc = fs.existsSync(path.resolve('babel.config.js'));
if (hasBabelRc) {
console.info('🐠 Using .babelrc defined in your app root');
}
module.exports = {
devtool: 'sourcemap',
entry: {
// We take care of setting up entry file under lib/index.js
index: ['graphpack'],
},
// When bundling with Webpack for the backend you usually don't want to bundle
// its node_modules dependencies. This creates an externals function that
// ignores node_modules when bundling in Webpack.
externals: [nodeExternals({ whitelist: [/^graphpack$/] })],
mode: IS_DEV ? 'development' : 'production',
module: {
rules: [
{
test: /\.graphql/,
use: 'graphql-tag/loader',
},
{
test: /\.js$/,
use: [
{
loader: require.resolve('babel-loader'),
options: {
babelrc: true,
cacheDirectory: true,
presets: hasBabelRc
? undefined
: [require.resolve('babel-preset-graphpack')],
},
},
],
},
{
test: /\.mjs$/,
type: 'javascript/auto',
},
],
},
node: {
__filename: true,
__dirname: true,
},
optimization: { noEmitOnErrors: true },
output: {
filename: '[name].js',
libraryTarget: 'commonjs2',
path: path.join(process.cwd(), './build'),
sourceMapFilename: '[name].map',
},
performance: {
hints: false,
},
plugins: [
new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1 }),
new webpack.EnvironmentPlugin({
DEBUG: false,
GRAPHPACK_SRC_DIR: path.resolve(process.cwd(), 'src'),
NODE_ENV: 'development',
}),
new FriendlyErrorsWebpackPlugin({ clearConsole: IS_DEV }),
],
stats: 'minimal',
target: 'node',
};