This repository was archived by the owner on Dec 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config-helper.js
99 lines (88 loc) · 2.19 KB
/
webpack.config-helper.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
'use strict'
const Path = require('path')
const Webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const ExtractSASS = new ExtractTextPlugin('styles/bundle.css')
module.exports = (options) => {
let webpackConfig = {
devtool: options.devtool,
entry: [
`webpack-dev-server/client?http://localhost:${options.port}`,
'webpack/hot/dev-server',
'./src/scripts/index'
],
output: {
path: Path.join(__dirname, 'dist'),
filename: 'bundle.js'
},
plugins: [
new Webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(options.isProduction ? 'production' : 'development')
}
}),
new HtmlWebpackPlugin({
template: './src/index.html'
}),
new Webpack.ProvidePlugin({
riot: 'riot'
})
],
module: {
preLoaders: [{
test: /\.tag$/,
exclude: /node_modules/,
include: /src/,
loader: 'riotjs-loader',
query: {
type: 'none'
}
}],
loaders: [{
test: /\.js$|\.tag$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['es2015']
}
}]
}
}
if (options.isProduction) {
webpackConfig.entry = ['./src/scripts/index']
webpackConfig.plugins.push(
new Webpack.optimize.OccurenceOrderPlugin(),
new Webpack.optimize.UglifyJsPlugin({
compressor: {
warnings: false
}
}),
ExtractSASS
)
webpackConfig.module.loaders.push({
test: /\.scss$/i,
loader: ExtractSASS.extract(['css', 'sass'])
})
} else {
webpackConfig.plugins.push(
new Webpack.HotModuleReplacementPlugin()
)
webpackConfig.module.loaders.push({
test: /\.scss$/i,
loaders: ['style', 'css', 'sass']
}, {
test: /\.js$/,
loader: 'eslint?{rules:{semi:0}}',
exclude: /node_modules/
})
webpackConfig.devServer = {
contentBase: './dist',
hot: true,
port: options.port,
inline: true,
progress: true
}
}
return webpackConfig
}