1 |
|
2 |
|
3 | const webpack = require('webpack');
|
4 | const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
|
5 | const path = require('path');
|
6 | const env = require('yargs').argv.env;
|
7 | const pkg = require('./package.json');
|
8 | const CleanWebpackPlugin = require('clean-webpack-plugin');
|
9 |
|
10 | process.env.BABEL_ENV = 'production';
|
11 | process.env.NODE_ENV = 'production';
|
12 |
|
13 | let libraryName = pkg.name;
|
14 |
|
15 | let plugins = [], outputFile;
|
16 |
|
17 | if (env.NODE_ENV === 'production') {
|
18 | plugins.push(new UglifyJsPlugin({ minimize: true }));
|
19 | outputFile = libraryName + '.min.js';
|
20 | } else {
|
21 | plugins.push(new CleanWebpackPlugin(['lib']));
|
22 | outputFile = libraryName + '.js';
|
23 | }
|
24 |
|
25 | const config = {
|
26 | entry: __dirname + '/src/index.js',
|
27 | devtool: 'source-map',
|
28 | output: {
|
29 | path: __dirname + '/lib',
|
30 | filename: outputFile,
|
31 | library: libraryName,
|
32 | libraryTarget: 'umd',
|
33 | umdNamedDefine: true
|
34 | },
|
35 | module: {
|
36 | rules: [
|
37 | {
|
38 | test: /(\.jsx|\.js)$/,
|
39 | loader: 'babel-loader',
|
40 | exclude: /(node_modules|bower_components)/
|
41 | },
|
42 | {
|
43 | test: /(\.jsx|\.js)$/,
|
44 | loader: 'eslint-loader',
|
45 | exclude: /node_modules/
|
46 | }
|
47 | ]
|
48 | },
|
49 | resolve: {
|
50 | modules: [path.resolve('./node_modules'), path.resolve('./src')],
|
51 | extensions: ['.json', '.js']
|
52 | },
|
53 | plugins: plugins,
|
54 | externals: {
|
55 | react: {
|
56 | root: 'React',
|
57 | commonjs2: 'react',
|
58 | commonjs: 'react',
|
59 | amd: 'react',
|
60 | }
|
61 | }
|
62 | };
|
63 |
|
64 | module.exports = config;
|