-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·129 lines (120 loc) · 2.94 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
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
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const postcssImport = require('postcss-import');
const extractSass = new ExtractTextPlugin({
filename: "[name].css"
});
const extractGithubCss = new ExtractTextPlugin({
filename: "gh.css"
});
const isProd = (
parseInt(process.env.PROD) === 1 ||
process.argv.some(x => /^(--)?p(rod(uction)?)?$/.test(x)) ||
/^(--)?p(rod(uction)?)?$/.test(process.env.NODE_ENV)
);
isProd && console.log('Compiling for production');
if (isProd) {
console.log('Converting docs');
require('child_process').execSync('node convert-docs.js');
}
const babelLoaderUseOptions = [{
loader: 'babel-loader',
options: {
presets: [
[
'@babel/preset-env',
{
modules: false,
browsers: ["last 2 versions"]
}
],
],
plugins: [
["@babel/transform-runtime", {
"helpers": false,
"polyfill": true,
"regenerator": true,
"moduleName": "@babel/runtime"
}]
]
}
}];
module.exports = {
entry: [
'./src/js/main.js',
'./src/css/main.scss',
'./src/css/github-markdown.css'
],
output: {
path: `${__dirname}/lib/`,
filename: '[name].js'
},
target: 'web',
devtool: isProd ? undefined : 'source-map',
plugins: [
extractSass,
extractGithubCss
],
module: {
rules: [
{
// need to babelify joi, isemail, hoek, and topo's lib
test: /[\\\/]node_modules[\\\/](joi[\\\/]lib[\\\/]|isemail[\\\/]lib[\\\/]|hoek[\\\/]lib[\\\/]|topo[\\\/]lib[\\\/])/,
use: babelLoaderUseOptions
},
{
test: /\.jsx?$/,
use: babelLoaderUseOptions,
exclude: [
path.resolve(__dirname, 'node_modules')
]
},
{
test: /github-markdown\.css$/,
loaders: extractGithubCss.extract({
use: [
{
loader: "css-loader",
}
]
})
},
{
test: /\.scss$/,
loader: extractSass.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
importLoaders: 2,
sourceMap: !isProd
}
},
{
loader: 'postcss-loader',
options: {
plugins: loader => [
postcssImport({ addDependencyTo: webpack }),
require('postcss-import')({ root: loader.resourcePath }),
require('autoprefixer')({ browsers: ['last 2 versions'] }),
require('cssnano')()
],
sourceMap: !isProd
}
},
{ loader: 'sass-loader', options: { sourceMap: !isProd } }
]
})
}
]
},
node: {
global: true,
Buffer: true,
crypto: 'empty',
net: 'empty',
dns: 'empty'
}
};