forked from cncjs/cncjs-widget-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
executable file
·160 lines (157 loc) · 4.88 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const pkg = require('./package.json');
const path = require('path');
const webpack = require('webpack');
const findImports = require('find-imports');
const WriteFileWebpackPlugin = require('write-file-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const stylusLoader = require('stylus-loader');
const nib = require('nib');
const outputPath = process.env.OUTPUT_PATH || 'dist';
const timestamp = new Date().getTime();
const webpackConfig = {
entry: {
app: [
path.resolve(__dirname, 'src/index.js')
]
},
output: {
path: path.resolve(__dirname, outputPath),
chunkFilename: `[name].chunk.js?_=${timestamp}`,
filename: `[name].bundle.js?_=${timestamp}`
},
externals: []
.concat(Object.keys(pkg.peerDependencies)),
module: {
rules: [
// http://survivejs.com/webpack_react/linting_in_webpack/
{
test: /\.jsx?$/,
loader: 'eslint-loader',
enforce: 'pre',
exclude: /node_modules/
},
{
test: /\.styl$/,
loader: 'stylint-loader',
enforce: 'pre'
},
{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /(node_modules|bower_components)/
},
{
test: /\.styl$/,
use: [
'style-loader',
'css-loader?camelCase&modules&importLoaders=1&localIdentName=[local]---[hash:base64:5]',
'stylus-loader'
],
exclude: [
path.resolve(__dirname, 'src/styles')
]
},
{
test: /\.styl$/,
use: [
'style-loader',
'css-loader',
'stylus-loader'
],
include: [
path.resolve(__dirname, 'src/styles')
]
},
{
test: /\.css$/,
loader: 'style-loader!css-loader'
},
{
test: /\.(png|jpg|svg|cur)$/,
loader: 'url-loader',
options: {
limit: 8192
}
},
{
test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url-loader',
options: {
limit: 10000,
mimetype: 'application/font-woff'
}
},
{
test: /\.(ttf|eot)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file-loader'
}
]
},
plugins: [],
resolve: {
extensions: ['.js', '.jsx']
}
};
if (process.env.NODE_ENV === 'development') {
webpackConfig.devtool = 'eval';
webpackConfig.plugins = [
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
NODE_ENV: JSON.stringify('development')
}
}),
new WriteFileWebpackPlugin(),
new webpack.NoEmitOnErrorsPlugin(),
new stylusLoader.OptionsPlugin({
default: {
// nib - CSS3 extensions for Stylus
use: [nib()],
// no need to have a '@import "nib"' in the stylesheet
import: ['~nib/lib/nib/index.styl']
}
}),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, outputPath, 'index.html'),
template: path.resolve(__dirname, 'assets/index.html')
})
];
} else {
webpackConfig.devtool = 'source-map';
webpackConfig.plugins = [
new webpack.DefinePlugin({
'process.env': {
// This has effect on the react lib size
NODE_ENV: JSON.stringify('production')
}
}),
new webpack.NoEmitOnErrorsPlugin(),
new stylusLoader.OptionsPlugin({
default: {
// nib - CSS3 extensions for Stylus
use: [nib()],
// no need to have a '@import "nib"' in the stylesheet
import: ['~nib/lib/nib/index.styl']
}
}),
new webpack.optimize.UglifyJsPlugin({
sourceMap: true,
compress: {
screw_ie8: true, // React doesn't support IE8
warnings: false
},
mangle: {
screw_ie8: true
},
output: {
comments: false,
screw_ie8: true
}
}),
new HtmlWebpackPlugin({
filename: path.resolve(__dirname, outputPath, 'index.html'),
template: path.resolve(__dirname, 'assets/index.html')
})
];
}
module.exports = webpackConfig;