-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.js
135 lines (135 loc) · 5.34 KB
/
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
"use strict";
const webpack = require('webpack');
const path = require('path');
const glob_copy_webpack_plugin_1 = require('../../plugins/glob-copy-webpack-plugin');
const package_chunk_sort_1 = require('../../utilities/package-chunk-sort');
const base_href_webpack_1 = require('../../lib/base-href-webpack');
const utils_1 = require('./utils');
const autoprefixer = require('autoprefixer');
const ProgressPlugin = require('webpack/lib/ProgressPlugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
/**
* Enumerate loaders and their dependencies from this file to let the dependency validator
* know they are used.
*
* require('source-map-loader')
* require('raw-loader')
* require('script-loader')
* require('json-loader')
* require('url-loader')
* require('file-loader')
*/
function getCommonConfig(wco) {
const { projectRoot, buildOptions, appConfig } = wco;
const appRoot = path.resolve(projectRoot, appConfig.root);
const nodeModules = path.resolve(projectRoot, 'node_modules');
let extraPlugins = [];
let extraRules = [];
let entryPoints = {};
// figure out which are the lazy loaded entry points
const lazyChunks = utils_1.lazyChunksFilter([
...utils_1.extraEntryParser(appConfig.scripts, appRoot, 'scripts'),
...utils_1.extraEntryParser(appConfig.styles, appRoot, 'styles')
]);
if (appConfig.main) {
entryPoints['main'] = [path.resolve(appRoot, appConfig.main)];
}
if (appConfig.polyfills) {
entryPoints['polyfills'] = [path.resolve(appRoot, appConfig.polyfills)];
}
// determine hashing format
const hashFormat = utils_1.getOutputHashFormat(buildOptions.outputHashing);
// process global scripts
if (appConfig.scripts.length > 0) {
const globalScripts = utils_1.extraEntryParser(appConfig.scripts, appRoot, 'scripts');
// add entry points and lazy chunks
globalScripts.forEach(script => {
let scriptPath = `script-loader!${script.path}`;
if (script.lazy) {
lazyChunks.push(script.entry);
}
entryPoints[script.entry] = (entryPoints[script.entry] || []).concat(scriptPath);
});
}
if (buildOptions.vendorChunk) {
extraPlugins.push(new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
chunks: ['main'],
minChunks: (module) => module.resource && module.resource.startsWith(nodeModules)
}));
}
// process asset entries
if (appConfig.assets) {
extraPlugins.push(new glob_copy_webpack_plugin_1.GlobCopyWebpackPlugin({
patterns: appConfig.assets,
globOptions: { cwd: appRoot, dot: true, ignore: '**/.gitkeep' }
}));
}
if (buildOptions.progress) {
extraPlugins.push(new ProgressPlugin({ profile: buildOptions.verbose, colors: true }));
}
return {
devtool: buildOptions.sourcemap ? 'source-map' : false,
resolve: {
extensions: ['.ts', '.js'],
modules: [nodeModules],
},
resolveLoader: {
modules: [nodeModules]
},
context: projectRoot,
entry: entryPoints,
target: 'electron-renderer',
output: {
path: path.resolve(projectRoot, buildOptions.outputPath),
publicPath: buildOptions.deployUrl,
filename: `[name]${hashFormat.chunk}.bundle.js`,
sourceMapFilename: `[name]${hashFormat.chunk}.bundle.map`,
chunkFilename: `[id]${hashFormat.chunk}.chunk.js`
},
module: {
rules: [
{ enforce: 'pre', test: /\.js$/, loader: 'source-map-loader', exclude: [nodeModules] },
{ test: /\.json$/, loader: 'json-loader' },
{ test: /\.node$/, loader: 'node-loader' },
{ test: /\.html$/, loader: 'raw-loader' },
{ test: /\.(eot|svg)$/, loader: `file-loader?name=[name]${hashFormat.file}.[ext]` },
{
test: /\.(jpg|png|gif|otf|ttf|woff|woff2|cur|ani)$/,
loader: `url-loader?name=[name]${hashFormat.file}.[ext]&limit=10000`
}
].concat(extraRules)
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(appRoot, appConfig.index),
filename: path.resolve(buildOptions.outputPath, appConfig.index),
chunksSortMode: package_chunk_sort_1.packageChunkSort(appConfig),
excludeChunks: lazyChunks,
xhtml: true
}),
new base_href_webpack_1.BaseHrefWebpackPlugin({
baseHref: buildOptions.baseHref
}),
new webpack.optimize.CommonsChunkPlugin({
minChunks: Infinity,
name: 'inline'
})
].concat(extraPlugins),
node: {
fs: true,
global: true,
crypto: 'empty',
tls: 'empty',
net: 'empty',
process: true,
module: false,
clearImmediate: false,
setImmediate: false
}
};
}
exports.getCommonConfig = getCommonConfig;
//# sourceMappingURL=/Users/hansl/Sources/angular-cli/packages/@angular/cli/models/webpack-configs/common.js.map