forked from ShuyunFF2E/ccms-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack-build.config.js
91 lines (89 loc) · 2.21 KB
/
webpack-build.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
/**
* @author Kuitos
* @homepage https://github.com/kuitos/
* @since 2015-08-06
*/
var path = require('path');
var webpack = require('webpack');
var autoprefixer = require('autoprefixer');
var CleanPlugin = require('clean-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var cssnano = require('cssnano');
var cssNanoCommonOpts = {
discardComments: {removeAll: true},
discardDuplicates: true,
discardOverridden: true,
discardUnused: true,
minifyGradients: true
};
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
var loaders = require('./webpack-common-loaders');
const { version } = require('./package.json');
loaders.push(
{
test: /\.(sc|c)ss$/,
loader: ExtractTextPlugin.extract('style', 'css?-minimize!postcss!resolve-url!sass?sourceMap'),
exclude: /(node_modules|bower_components)/
}
);
module.exports = {
devtool: 'cheap-source-map',
entry: {
'ccms-components': './src/index.js',
'ccms-components.min': './src/index.js'
},
output: {
path: path.join(__dirname, 'dist'),
filename: '[name].js'
},
externals: {
'angular': 'angular',
'angular-resource': '\'ngResource\'',
'angular-ui-router': '\'ui.router\''
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify('production'),
VERSION: JSON.stringify(version)
}
}),
new CleanPlugin(['dist']),
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
minimize: true
}),
new ExtractTextPlugin('[name].css'),
// 处理extract出来的css
new OptimizeCssAssetsPlugin({
assetNameRegExp: /\.css$/g,
cssProcessor: cssnano({reduceIdents: false}),
cssProcessorOptions: Object.assign({
core: false
}, cssNanoCommonOpts),
canPrint: true
}),
new webpack.optimize.DedupePlugin(),
new webpack.NoErrorsPlugin()
],
resolve: {
extensions: ['', '.js']
},
eslint: {
emitWarning: true,
emitError: true,
formatter: require('eslint-friendly-formatter')
},
postcss: [autoprefixer({browsers: ['Chrome > 35', 'Firefox > 30', 'Safari > 7']})],
module: {
preLoaders: [
{
test: /\.js?$/,
loader: 'eslint-loader',
exclude: /node_modules/,
include: path.join(__dirname, 'src')
}
],
loaders: loaders
}
};