forked from LaxarJS/laxar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
120 lines (100 loc) · 3.25 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
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
/**
* Copyright 2017 aixigo AG
* Released under the MIT license.
* http://laxarjs.org/license
*/
/* eslint-env node */
const path = require( 'path' );
const webpack = require( 'webpack' );
const nodeEnv = process.env.NODE_ENV;
const isProduction = nodeEnv === 'production';
const isBrowserSpec = nodeEnv === 'browser-spec';
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
const baseConfig = {
devtool: '#source-map',
entry: {
laxar: './laxar.js',
polyfills: './polyfills.js'
},
module: {
noParse: /node_modules[/\\]page[/\\]page\.js/,
rules: [
{
test: /\.js$/,
exclude: path.resolve( __dirname, 'node_modules' ),
loader: 'babel-loader'
}
]
}
};
const config = isProduction ? distConfig() : baseConfig;
if( isBrowserSpec ) {
const WebpackJasmineHtmlRunnerPlugin = require( 'webpack-jasmine-html-runner-plugin' );
config.entry = Object.assign(
WebpackJasmineHtmlRunnerPlugin.entry( './lib/*/spec/spec-runner.js' ),
baseConfig.entry
);
config.plugins = [ new WebpackJasmineHtmlRunnerPlugin() ];
config.output = {
path: path.resolve( path.join( process.cwd(), 'spec-output' ) ),
publicPath: '/spec-output/',
filename: '[name].bundle.js'
};
}
module.exports = config;
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function distConfig() {
return [
distConfigItem( './laxar.js', 'laxar.js' ),
distConfigItem( './laxar.js', 'laxar.min.js', { minify: true } ),
distConfigItem( './laxar.js', 'laxar.with-deps.js', { externals: {} } ),
distConfigItem( './laxar.js', 'laxar.with-deps.min.js', { minify: true, externals: {} } ),
distConfigItem(
'./laxar-compatibility.js',
'laxar-compatibility.with-deps.js',
{ externals: {} }
),
distConfigItem(
'./laxar-widget-service-mocks.js',
'laxar-widget-service-mocks.js',
{ externals: { laxar: 'laxar' }, library: 'laxar-widget-service-mocks' }
),
distConfigItem(
'./polyfills.js',
'polyfills.js', { externals: {}, library: false }
)
];
function distConfigItem( entry, output, optionalOptions ) {
const options = Object.assign( {
minify: false,
externals: { 'navigo': 'navigo' },
library: 'laxar'
}, optionalOptions || {} );
const config = Object.assign( {}, baseConfig );
config.entry = entry;
config.output = {
path: path.resolve( __dirname ),
filename: `dist/${output}`,
umdNamedDefine: true
};
if( options.library !== false ) {
config.output.library = options.library;
config.output.libraryTarget = 'umd';
}
config.externals = options.externals;
config.plugins = [
new webpack.SourceMapDevToolPlugin( {
filename: `dist/${output}.map`
} )
];
if( options.minify ) {
config.plugins.push(
new webpack.optimize.UglifyJsPlugin( {
compress: { warnings: false },
sourceMap: true
} )
);
}
return config;
}
}