-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathwebpack.config.js
More file actions
75 lines (54 loc) · 1.79 KB
/
webpack.config.js
File metadata and controls
75 lines (54 loc) · 1.79 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
// webpack.config.js
// For library build
const path = require("path");
const glob = require("glob");
const nodeExternals = require('webpack-node-externals');
process.env.NODE_ENV='production';
const library = 'wordpress-rest-admin';
const getEntries = entryPath => {
if(0 >= entryPath.length)
return null;
// e.g. containers/**/*.js
const entries = glob.sync('./src/' + entryPath.shift())
.reduce( (entries, entry) => {
const key = entry.replace('./src/', '').replace('.js', '');
// Skip test files
if(!entry.match(/.test./))
return Object.assign(entries, {[key]: entry})
return entries
}, {})
return Object.assign(entries, getEntries(entryPath));
}
const getNpmConfig = (varname, _default) => {
return process.env["npm_config_" + varname] || _default;
}
// glob path to set the entry point
const entryPath = getNpmConfig('entryPath', null);
// Path for output files
const outputPath = getNpmConfig('outputPath', path.resolve(__dirname, "dist"));
const entries = !entryPath
? {WPAdmin: "./src/WPAdmin.js"}
: getEntries(entryPath.split(","));
module.exports = {
entry: entries,
output: {
path: outputPath,
filename: "[name].js",
library: [library, "[name]"],
libraryTarget: 'commonjs2'
},
externals: [nodeExternals()],
devtool: "source-map",
module: {rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: ["babel-loader", "eslint-loader"]
},{
test: /\.css$/,
use: [ 'style-loader', 'css-loader' ]
},{
loader: require.resolve('file-loader'),
exclude: [/\.(js|jsx|mjs|css)$/, /\.html$/, /\.json$/],
options: { name: '[name].[ext]' }
}]}
}