-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
136 lines (114 loc) · 3.4 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'use strict';
/* eslint-env node */
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const cssnext = require('postcss-cssnext');
const csso = require('postcss-csso');
const ENV = process.env.NODE_ENV || 'dev';
const isProd = ENV === 'production';
const DIR = {
src: path.join(__dirname, 'src'),
dist: path.join(__dirname, 'dist')
};
const config = {
entry: {
'main': './src/app/app.js'
},
output: {
path: './dist',
filename: '[name].bundle.js',
chunkFilename: '[id].chunk.js'
},
target: 'electron',
devtool: 'source-map',
resolve: {
modulesDirectories: ['node_modules'],
alias: {
compat: path.join(DIR.src, 'compat'),
images: path.join(DIR.src, 'images'),
svg: path.join(DIR.src, 'svg'),
common: path.join(DIR.src, 'app', 'common')
// components: path.join(DIR.src, 'components'),
// services: path.join(DIR.src, 'services')
}
},
plugins: [
new CleanWebpackPlugin([DIR.dist], {
root: __dirname,
verbose: true
}),
new ExtractTextPlugin('[name].css'),
new HtmlWebpackPlugin({
template: 'src/index.html',
inject: 'body'
}),
new webpack.HotModuleReplacementPlugin(),
// new webpack.optimize.CommonsChunkPlugin({
// name: 'main',
// async: true
// }),
new webpack.ProvidePlugin({
loki: 'lokijs'
}),
new CopyWebpackPlugin([
{from: `${DIR.src}/images/spinner.svg`, to: 'images'},
{from: `${DIR.src}/.package.json`, to: 'package.json'},
{from: `${DIR.src}/main.js`}
])
],
module: {
preLoaders: [
{
test: /\.js$/,
loader: 'eslint',
exclude: /node_modules/
}
],
loaders: [
{
test: /\.png$/,
loader: 'url'
},
{
test: /\.js$/,
loader: `${isProd ? 'ng-annotate!' : ''}babel`,
exclude: /node_modules/
},
{
test: /\.html$/,
loader: 'html'
},
{
test: /\.(less|css)$/,
loader: ExtractTextPlugin.extract('style-loader', 'css?root=~images&sourceMap!postcss?sourceMap')
},
{
test: /\.svg$/,
loader: `svg-sprite?${JSON.stringify({
name: '[name]',
angularBaseWorkaround: true
})}`
}
]
},
postcss: () => {
return [cssnext, csso];
}
};
// Add build specific plugins
if (isProd) {
config.devtool = '';
config.plugins.push(
// Only emit files when there are no errors
new webpack.NoErrorsPlugin(),
// Dedupe modules in the output
new webpack.optimize.DedupePlugin(),
// Minify all javascript, switch loaders to minimizing mode
new webpack.optimize.UglifyJsPlugin()
)
}
module.exports = config;