-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.conf.js
148 lines (131 loc) · 3.74 KB
/
webpack.conf.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
136
137
138
139
140
141
142
143
144
145
146
147
148
var path = require('path');
// Helper functions
var ROOT = path.resolve(__dirname);
const EVENT = process.env.npm_lifecycle_event || '';
function hasProcessFlag(flag) {
return process.argv.join('').indexOf(flag) > -1;
}
function hasNpmFlag(flag) {
return EVENT.includes(flag);
}
function isWebpackDevServer() {
return process.argv[1] && !! (/webpack-dev-server/.exec(process.argv[1]));
}
function root(args) {
args = Array.prototype.slice.call(arguments, 0);
return path.join.apply(path, [ROOT].concat(args));
}
const helpers = {};
helpers.hasProcessFlag = hasProcessFlag;
helpers.hasNpmFlag = hasNpmFlag;
helpers.isWebpackDevServer = isWebpackDevServer;
helpers.root = root;
const webpack = require('webpack');
/**
* Webpack Plugins
*/
const ProvidePlugin = require('webpack/lib/ProvidePlugin');
const DefinePlugin = require('webpack/lib/DefinePlugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
module.exports = {
devtool: 'source-map',
resolve: {
extensions: ['.ts', '.js']
},
entry: './src/lib/index.ts',
output: {
path: helpers.root('bundle'),
filename: 'cause.js',
libraryTarget: 'commonjs2',
library: 'cause'
},
// require those dependencies but don't bundle them
externals: [
/^\@angular\//,
/^rxjs\//,
/^md2/,
/^ts-md5/,
/^@ngx-translate/,
/^zone.js/,
/^ieee754/,
/^node-libs-browser/,
/^base64-js/
],
module: {
rules: [{
test: /\.ts$/,
use: [{
loader: 'awesome-typescript-loader?declaration=false',
options: {
tsconfig: './src/tsconfig.lib.json'
}
},
{
loader: 'angular2-template-loader'
}
],
exclude: [/\.(spec|e2e)\.ts$/]
},
{
test: /\.html$/,
use: ['raw-loader']
},
{
test: /\.css$/,
use: ['to-string-loader', 'css-loader']
},
{
test: /\.styl$/,
use: ['to-string-loader', 'css-loader', 'stylus-loader']
}
]
},
plugins: [
new ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)src(\\|\/)linker/,
helpers.root('src/lib'), // location of your web
{}
),
// Fix Angular 2
new NormalModuleReplacementPlugin(
/facade(\\|\/)async/,
helpers.root('node_modules/@angular/core/src/facade/async.js')
),
new NormalModuleReplacementPlugin(
/facade(\\|\/)collection/,
helpers.root('node_modules/@angular/core/src/facade/collection.js')
),
new NormalModuleReplacementPlugin(
/facade(\\|\/)errors/,
helpers.root('node_modules/@angular/core/src/facade/errors.js')
),
new NormalModuleReplacementPlugin(
/facade(\\|\/)lang/,
helpers.root('node_modules/@angular/core/src/facade/lang.js')
),
new NormalModuleReplacementPlugin(
/facade(\\|\/)math/,
helpers.root('node_modules/@angular/core/src/facade/math.js')
),
new LoaderOptionsPlugin({
minimize: true,
debug: false,
options: {
htmlLoader: {
minimize: true,
removeAttributeQuotes: false,
caseSensitive: true,
customAttrSurround: [
[/#/, /(?:)/],
[/\*/, /(?:)/],
[/\[?\(?/, /(?:)/]
],
customAttrAssign: [/\)?\]?=/]
},
}
})
]
};