forked from benmag1/mdl-ext
-
Notifications
You must be signed in to change notification settings - Fork 1
/
webpack.config.js
141 lines (134 loc) · 3.53 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
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 css_loader = [
'css-loader?sourceMap',
'postcss-loader'
].join('!');
const sass_loader = [
'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 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', sass_loader)
},
{
test: /\.css$/,
include: path.join(__dirname, 'src'),
loader: ExtractTextPlugin.extract('style-loader', css_loader)
}
]
},
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()
],
devServer: {
contentBase: './src',
port: 8080,
progress: true,
colors: true,
hot: true, // adds the HotModuleReplacementPlugin.
historyApiFallback: false, // when false, dev server make directory listing, good feature to navigate in project
quiet: false,
noInfo: false,
lazy: false,
aggregateTimeout: 300,
}
};
module.exports = config;