This repository has been archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
webpack.config.js
93 lines (80 loc) · 2.46 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
'use strict'
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const LessPluginCleanCSS = require('less-plugin-clean-css')
const LessPluginAutoPrefix = require('less-plugin-autoprefix')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const SplitByPathPlugin = require('webpack-split-by-path')
const isProduction = process.env.NODE_ENV === 'production'
const ROOT_FOLDER = path.resolve(__dirname)
const SRC_FOLDER = path.join(ROOT_FOLDER, 'client')
const CONFIG_FOLDER = path.join(ROOT_FOLDER, 'config')
const DIST_FOLDER = path.join(ROOT_FOLDER, 'public')
const entry = {
app: ['babel-polyfill', path.join(SRC_FOLDER, 'app/index.js')]
}
const plugins = [
new HtmlWebpackPlugin({
inject: 'head',
template: path.join(SRC_FOLDER, 'index.html')
}),
new webpack.NoErrorsPlugin(),
// env
new webpack.DefinePlugin({
'process.env.NODE_ENV': `${process.env.NODE_ENV}`
}),
new SplitByPathPlugin([{
name: 'vendors',
path: path.join(`${__dirname}/../node_modules`)
}]),
new ExtractTextPlugin(isProduction ? 'style/[name].[chunkhash].css' : 'style/[name].css')
]
if (isProduction) {
plugins.push(new webpack.optimize.UglifyJsPlugin({ minimize: true }))
}
const webpackConfig = {
devtool: 'source-map',
entry: entry,
output: {
publicPath: '/', // This is used for generated urls
path: DIST_FOLDER,
filename: isProduction ? 'script/[name].[chunkhash].js' : 'script/[name].js',
chunkFilename: isProduction ? 'script/[name].[chunkhash].js' : 'script/[name].js'
},
plugins: plugins,
resolve: {
alias: {
'xively-client': path.join(ROOT_FOLDER, 'client/vendor/xively-client')
}
},
resolveLoader: {
fallback: path.join(ROOT_FOLDER, 'node_modules')
},
lessLoader: {
lessPlugins: [
new LessPluginAutoPrefix({ browsers: ['last 2 versions'] }),
new LessPluginCleanCSS({ advanced: true })
]
},
module: {
loaders: [{
test: /\.js$/,
loaders: ['ng-annotate', 'babel'],
exclude: /node_modules/,
include: [SRC_FOLDER, CONFIG_FOLDER]
}, {
test: /(\.less$|\.css$)/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap!less-loader?sourceMap')
}, {
test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192'
}, {
test: /\.svg$/,
loader: 'svg-inline'
}, {
test: /\.html$/,
loader: 'html'
}]
}
}
module.exports = webpackConfig