This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
116 lines (105 loc) · 3.86 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
/**
* Copyright 2017 aixigo AG
* Released under the MIT license.
* https://laxarjs.org/license
*/
/* eslint-env node */
const path = require( 'path' );
const webpack = require( 'webpack' );
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
const WebpackJasmineHtmlRunnerPlugin = require( 'webpack-jasmine-html-runner-plugin' );
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
module.exports = ( env = {} ) =>
env.browserSpec ?
Object.assign( config( env ), {
entry: WebpackJasmineHtmlRunnerPlugin.entry( './application/widgets/**/spec/*.spec.js' ),
output: {
path: resolve( 'spec-output' ),
publicPath: '/spec-output/',
filename: '[name].bundle.js'
}
} ) :
config( env );
function config( env ) {
const outputPath = env.production ? 'dist/' : 'build/';
return {
devtool: '#source-map',
entry: { 'init': './init.js' },
output: {
path: resolve( `./${outputPath}` ),
publicPath: outputPath,
filename: env.production ? '[name].bundle.min.js' : '[name].bundle.js',
chunkFilename: env.production ? '[name].bundle.min.js' : '[name].bundle.js'
},
plugins: env.production ? [
new ExtractTextPlugin( { filename: '[name].bundle.css' } ),
new webpack.optimize.UglifyJsPlugin()
] : [
new WebpackJasmineHtmlRunnerPlugin()
],
resolve: {
modules: [ resolve( 'node_modules' ) ],
extensions: [ '.js' ],
alias: {
'default.theme': 'laxar-uikit/themes/default.theme',
'cube.theme': 'laxar-cube.theme'
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: resolve( 'node_modules' ),
loader: 'babel-loader'
},
{
test: /.spec.js$/,
exclude: resolve( 'node_modules' ),
loader: 'laxar-mocks/spec-loader'
},
{ // load styles, images and fonts with the file-loader
// (out-of-bundle in build/assets/)
test: /\.(gif|jpe?g|png|ttf|woff2?|svg|eot|otf)(\?.*)?$/,
loader: 'file-loader',
options: {
name: env.production ? 'assets/[name]-[sha1:hash:8].[ext]' : 'assets/[path]-[name].[ext]'
}
},
{ // ... after optimizing graphics with the image-loader ...
test: /\.(gif|jpe?g|png|svg)$/,
loader: 'img-loader?progressive=true'
},
{ // ... and resolving CSS url()s with the css loader
// (extract-loader extracts the CSS string from the JS module returned by the css-loader)
test: /\.(css|s[ac]ss)$/,
loader: env.production ?
ExtractTextPlugin.extract( {
fallback: 'style-loader',
use: env.production ? 'css-loader' : 'css-loader?sourceMap',
publicPath: ''
} ) :
'style-loader!css-loader?sourceMap'
},
{
test: /[/]default[.]theme[/].*[.]s[ac]ss$/,
loader: 'sass-loader',
options: Object.assign(
{},
require( 'laxar-uikit/themes/default.theme/sass-options' ),
{ sourceMap: true }
)
},
{
test: /[/](laxar-)?cube[.]theme[/].*[.]s[ac]ss$/,
loader: 'sass-loader',
options: Object.assign(
{},
require( 'laxar-cube.theme/sass-options' ),
{ sourceMap: true }
)
}
]
}
};
}
function resolve( p ) { return path.resolve( __dirname, p ); }