-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
61 lines (59 loc) · 1.98 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
/**
* Created by cashsun on 2016/10/19.
*/
var path = require('path');
var argv = require('yargs').argv;
var os = require('os');
var webpack = require('webpack');
var tmpdir = os.tmpdir();
console.log('tmpdir', tmpdir);
var workingDir = process.cwd();
var configPath = argv.config || 'rehearse.config.js';
var config = require(path.join(workingDir, configPath));
var VIEWER = 'rehearse-viewer';
var webpackOverride = config.webpack || {};
var overrideLoaders = webpackOverride.overrideLoaders;
var overridePlugins = webpackOverride.overridePlugins;
var additionalWebpackLoaders = webpackOverride.loaders || [];
var additionalWebpackPlugins = webpackOverride.plugins || [];
var modulesDirectories = webpackOverride.modulesDirectories;
var additionalEntry = webpackOverride.entry || [];
var additionalAlias = webpackOverride.alias || {};
var webpackConfig = {
cache: true,
resolve: {
alias: Object.assign({
rehearse: __dirname
}, additionalAlias),
root: [
path.join(__dirname, 'node_modules'),
path.join(workingDir, 'node_modules'),
path.resolve(__dirname)
],
modulesDirectories
},
entry: [
'webpack/hot/only-dev-server',
'react-hot-loader/patch',
path.join(workingDir, `${VIEWER}.js`),
].concat(additionalEntry),
module: {
loaders: overrideLoaders ? additionalWebpackLoaders : [
{
test: /\.js$/,
exclude: /(node_modules)(?!.{1}rehearse)/,
loaders: [ 'babel-loader', 'react-hot-loader/webpack']
},
].concat(additionalWebpackLoaders)
},
devtool: webpackOverride.devtool || 'eval',
output: {
filename: `${VIEWER}.build.js`,
publicPath: '/viewer',
path: path.resolve(tmpdir)
},
plugins: overridePlugins ? additionalWebpackPlugins : [
new webpack.HotModuleReplacementPlugin()
].concat(additionalWebpackPlugins)
};
module.exports = webpackConfig;