-
Notifications
You must be signed in to change notification settings - Fork 42
/
webpack.build.js
92 lines (83 loc) · 2.37 KB
/
webpack.build.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
var config = require('./webpack.config.js')
var webpack = require('webpack')
var optimist = require('optimist')
var pkg = require('./package.json')
var ExtractTextPlugin = require('extract-text-webpack-plugin')
// get some options
var ENV = optimist.argv.env || 'development'
var BUNDLE = optimist.argv.bundle || false
// file name
var fileName = (ENV === 'production') ? './dist/[name].min' : './dist/[name]'
if (BUNDLE) {
fileName = (ENV === 'production') ? './dist/[name]-bundle.min' : './dist/[name]-bundle'
}
/**
* define environment
*/
// set an environment variable to be available in the build script
config.plugins = []
if (ENV) {
config.plugins.push(new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"' + ENV + '"'
}
}))
}
// define plugins for production
if (ENV === 'production') {
config.plugins.push(new webpack.optimize.UglifyJsPlugin({
sourceMap: false,
compress: {
warnings: false
}
}))
}
/**
* define devtool for source maps
*/
if (ENV === 'development' && !BUNDLE) {
config.devtool = 'source-map'
}
/**
* define scss loaders
* in docs we want css stuff served from static bundle js that has css and js included
*/
if (ENV === 'docs' || BUNDLE) {
config.module.loaders.push({
test: /\.scss$/,
loader: 'style-loader!css-loader!autoprefixer-loader!sass-loader!vuestrap-theme-loader'
})
} else {
config.plugins.push(new ExtractTextPlugin(fileName + '.css'))
config.module.loaders.push({
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!autoprefixer-loader!sass-loader!vuestrap-theme-loader')
})
}
/**
* define entry
* if docs get everything, including styling, all source components and docs compoenents
* otherwise just load source components
*/
if (ENV !== 'docs') {
config.entry = {}
config.entry[pkg.library] = './src/components/compiled.js'
} else {
config.entry = './src/index.js'
}
/**
* define output
* creates bundle files that include css and js -> this is a main script in package.json
* creates seperate styling and js files -> these files will be included in bower
* creates docs bundle file that includes everything -> used in index.html (gh_pages)
*/
config.output = (ENV !== 'docs') ? {
filename: fileName + '.js',
library: pkg.library,
libraryTarget: 'umd'
} : {
path: './dist',
publicPath: '/dist/',
filename: 'docs.js'
}
module.exports = config