-
Notifications
You must be signed in to change notification settings - Fork 16
/
webpack.config.js
100 lines (93 loc) · 2.52 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
const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const nodeExternals = require('webpack-node-externals')
const autoprefixer = require('autoprefixer')
const path = require('path')
const isProductionMode = ~process.argv.indexOf('-p')
const outputDir = isProductionMode ? 'dist' : '.build'
const commandFiles = ['', '-create', '-server', '-deploy', '-help'].map( command => {
return `lagom${command}`;
})
const commonOptions = {
resolve: {
extensions: ['', '.js', '.sass'],
modulesDirectories: ['src', 'node_modules']
}
}
const binConfigs = commandFiles.map(commandFile => {
return Object.assign({}, commonOptions, {
entry: `./src/bin/${commandFile}.js`,
target: 'node',
node: {
__dirname: false,
__filename: false,
},
module: {
preLoaders: [{
test: /\.js$/, loader: "eslint-loader", exclude: /node_modules/
}],
loaders: [{
loader: 'babel',
test: /\.js?$/,
exclude: /node_modules/
}]
},
plugins: [
new webpack.BannerPlugin('#!/usr/bin/env node', { raw: true })
],
output: {
filename: `${outputDir}/bin/${commandFile}`
},
externals: [ nodeExternals() ]
})
})
const starterConfig = Object.assign({}, commonOptions, {
entry: './src/lagom.js',
module: {
preLoaders: [{
test: /\.js$/, loader: "eslint-loader", exclude: /node_modules/
}],
loaders: [{
test: /\.html$/,
loader: 'html',
query: {
minimize: false
}
},{
test: /\.js?$/,
loader: 'babel',
exclude: /node_modules/
}, {
test: /\.scss$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract(
'style', // The backup style loader
'css-loader!postcss-loader!sass-loader'
),
}]
},
output: {
filename: `${outputDir}/starter/scripts/lagom.js`
},
sassLoader: {
includePaths: [ 'src/styles' ]
},
postcss: function () {
return [autoprefixer({browsers: ['last 5 versions']})];
},
plugins: [
new HtmlWebpackPlugin({
template: 'src/index.html',
filename: `${outputDir}/starter/index.html`,
inject: false
}),
new ExtractTextPlugin(`${outputDir}/starter/styles/lagom.css`),
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': isProductionMode ? JSON.stringify('production') : JSON.stringify('development')
}
})
]
})
module.exports = binConfigs.concat(starterConfig)