-
Notifications
You must be signed in to change notification settings - Fork 12
/
webpack.common.js
114 lines (101 loc) · 2.92 KB
/
webpack.common.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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack');
const externalsFn = (function () {
const IGNORES = [
'node-core-audio',
'electron'
];
return function (context, request, callback) {
if (IGNORES.indexOf(request) >= 0) {
return callback(null, "require('" + request + "')");
}
return callback();
};
})();
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [__dirname].concat(args));
}
function makeRenderConfig(name, entryFile, indexHtml, prodMode) {
let config = {};
config.name = name;
if (prodMode) {
config.devtool = 'eval';
} else {
config.devtool = 'eval-source-map';
}
config.node = {
__dirname: false,
__filename: false
};
config.target = 'electron-renderer';
config.entry = {
[name]: entryFile
};
config.output = {
path: root('app'),
filename: '[name].js'
};
config.resolve = {
// only discover files that have those extensions
extensions: ['.ts', '.js', '.json', '.css', '.scss', '.html']
};
config.module = {
loaders: [
{
test: /\.ts$/,
loaders: /*aotMode ? ['@ngtools/webpack'] :*/ ['ts-loader', 'angular2-template-loader']
},
{test: /\.(svg|png|jpe?g|gif|woff|woff2|ttf|eot|ico)$/, loader: 'file-loader?name=assets/[name].[ext]?'},
{test: /\.css$/, loader: 'raw-loader'},
{test: /\.s[ac]ss$/, loader: 'raw-loader!sass-loader'},
{test: /\.html$/, loader: 'html-loader'}
],
noParse: [
/.+zone\.js\/dist\/.+/,
/.+angular2\/bundles\/.+/,
/angular2-polyfills\.js/,
/node_modules\/json-schema\/lib\/validate\.js/
]
};
config.plugins = [
new HtmlWebpackPlugin({
inject: true,
template: indexHtml
}),
new webpack.DefinePlugin({
VERSION: JSON.stringify(require('./package.json').version)
}),
new webpack.LoaderOptionsPlugin({
options: {
context: __dirname,
sassLoader: {
includePaths: [path.resolve(__dirname, "./src/render/styles/")]
},
resolve: {
extensions: ['.ts', '.tsx', '.js']
}
}
})
];
if (prodMode) {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
},
output: {
comments: false,
}
})
);
}
config.externals = [externalsFn];
return config;
}
module.exports = {
externalsFn,
root,
makeRenderConfig
};