-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
102 lines (89 loc) · 3.3 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
var path = require('path');
var webpack = require('webpack');
var UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
var path = require('path');
var env = require('yargs').argv.mode;
var libraryName = 'Deslider';
const ExtractTextPlugin = require('extract-text-webpack-plugin');
var OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
var plugins = [];
var outputFile;
if (env === 'build') {
plugins.push(new UglifyJsPlugin({ minimize: true }));
outputFile = libraryName + '.min.js';
plugins.push(new ExtractTextPlugin("../css/style.min.css"));
plugins.push(new OptimizeCssAssetsPlugin({
//assetNameRegExp: /\.min\.css$/,
// default is /\.css$/g
cssProcessorOptions: { discardComments: { removeAll: true } }
}));
} else {
plugins.push(new ExtractTextPlugin("../css/style.css"));
outputFile = libraryName + '.js';
}
var config = {
watch: true,
entry: [ __dirname + '/src/main.js' ],
devtool: 'source-map',
output: {
path: __dirname + '/lib',
filename: outputFile,
library: libraryName,
libraryTarget: 'umd'
},
module: {
preLoaders: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'jshint-loader'
}
],
loaders: [
{
test: /(\.jsx|\.js)$/,
loader: "babel!eslint-loader",
exclude: /(node_modules|bower_components)/
},
{
test: /\.css$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!autoprefixer-loader")
},
{
test: /\.scss$/,
exclude: /node_modules/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader!autoprefixer-loader!sass-loader")
},
]
},
resolve: {
// root: path.resolve('./src'),
extensions: ['', '.js']
},
plugins: plugins
};
module.exports = config;
/*
* __dirname refers to the diretory where this webpack.config.js lives
* https://julienrenaux.fr/2015/03/30/introduction-to-webpack-with-practical-examples/
*/
/*
// https://github.com/webpack/webpack/issues/2764
// http://stackoverflow.com/questions/29210325/webpack-sass-where-is-the-css-file
// http://stackoverflow.com/questions/35637184/minify-css-from-webpacks-extracttextplugin-and-style-loader
// http://stackoverflow.com/questions/40356445/webpack-how-to-compile-scss-into-a-separate-css-file
// https://blog.madewithenvy.com/getting-started-with-webpack-2-ed2b86c68783#.k9j27f5vs
// https://robinwieruch.de/react-eslint-webpack-babel/#eslintBabel
// http://blog.brew.com.hk/getting-started-with-webpack/
// https://www.sitepoint.com/javascript-modules-bundling-transpiling/
// https://qconsf.com/system/files/presentation-slides/webpack-_one_build_step_to_rule_them_all.pdf
// https://www.codementor.io/javascript/tutorial/module-bundler-webpack-getting-started-guide
// https://www.gitbook.com/book/abhijeetnmishra/webpack-step-by-step/details
// https://www.bensmithett.com/smarter-css-builds-with-webpack/
// https://gist.github.com/nkbt/9efd4facb391edbf8048
// https://robinwieruch.de/react-eslint-webpack-babel/
// http://krasimirtsonev.com/blog/article/javascript-library-starter-using-webpack-es6
// https://www.sitepoint.com/transpiling-es6-modules-to-amd-commonjs-using-babel-gulp/
// http://guybedford.com/practical-workflows-for-es6-modules
*/