-
Notifications
You must be signed in to change notification settings - Fork 29
/
webpack.config.js
140 lines (134 loc) · 3.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
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
if (!global.Promise) {
console.log("require es6-promise");
global.Promise = require('es6-promise').polyfill();
}
const webpack = require('webpack');
const path = require('path');
const autoprefixer = require('autoprefixer');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const StyleLintPlugin = require('stylelint-webpack-plugin');
const env = require('yargs').argv.mode;
const scss = [
'css-loader?sourceMap',
'postcss-loader',
'resolve-url-loader',
'sass-loader?sourceMap&expanded'
].join('!');
const libraryName = 'mdl-ext';
const cssName = 'mdl-ext';
var outputFile;
var outputCss;
var outputCssEqJs;
if (env === 'build') {
outputFile = libraryName + '.min.js';
outputCss = '[name].min.css';
outputCssEqJs = cssName + '-eqjs.min.css';
}
else {
outputFile = libraryName + '.js';
outputCss = '[name].css';
outputCssEqJs = cssName + '-eqjs.css';
}
var prodPlugins = env === 'build' ? [
new webpack.optimize.UglifyJsPlugin({
compress: {
unused: true, // Enables tree shaking
dead_code: true, // Enables tree shaking
pure_getters: true,
warnings: false,
screw_ie8: true,
conditionals: true,
comparisons: true,
sequences: true,
evaluate: true,
join_vars: true,
if_return: true,
},
output: {
comments: false
},
sourceMap: true
}),
] : [];
var config = {
entry: {
'mdl-ext': [
path.join(__dirname, 'src/mdl-ext-build.scss'), // MDLEXT Styles
path.join(__dirname, 'src/index.js') // MDLEXT scripts
],
'mdl-ext-eqjs': [
path.join(__dirname, 'src/mdl-ext-eqjs-build.scss'), // MDLEXT Styles based on eq.js
path.join(__dirname, 'src/index.js') // MDLEXT scripts
],
},
devtool: 'source-map',
output: {
path: path.join(__dirname, 'lib'),
filename: outputFile,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
preLoaders: [
{
loader: 'eslint',
test: /\.js[x]?$/,
include: [ // ... or: exclude: /(node_modules|bower_components)/,
path.join(__dirname, 'src'),
path.join(__dirname, 'test')
]
}
],
loaders: [
{
test: /\.js[x]?$/,
loader: 'babel',
exclude: /(node_modules|bower_components)/
},
{
test: /\.scss$/,
include: path.join(__dirname, 'src'),
loader: ExtractTextPlugin.extract('style-loader', scss)
},
]
},
sassLoader: {
includePaths: [
path.resolve(__dirname, './node_modules'),
path.resolve(__dirname, './src')
]
},
postcss: [
autoprefixer({
browsers: ['last 2 versions']
})
],
eslint: {
// config in '.eslintrc'
failOnWarning: false,
failOnError: true
},
resolve: {
root: path.resolve('./src'),
modulesDirectories: ['src', 'node_modules'],
extensions: ['', '.js', '.jsx', '.css', '.scss', 'html']
},
plugins: [
new ExtractTextPlugin(outputCss, {
disable: false,
allChunks: true
}),
new StyleLintPlugin({
// http://stylelint.io/user-guide/example-config/
configFile: '.stylelintrc',
context: 'src',
files: '**/*.s?(a|c)ss',
syntax: 'scss',
failOnError: false
}),
new webpack.optimize.DedupePlugin(),
new webpack.optimize.OccurrenceOrderPlugin()
].concat(prodPlugins),
};
module.exports = config;