1 | import webpack from 'webpack';
|
2 | import path from 'path';
|
3 | import chalk from 'chalk';
|
4 |
|
5 | import BuildNotifierPlugin from 'webpack-build-notifier';
|
6 | import HtmlWebpackPlugin from 'html-webpack-plugin';
|
7 | import ProgressBarPlugin from 'progress-bar-webpack-plugin';
|
8 | import WebpackShellPlugin from '@slightlytyler/webpack-shell-plugin';
|
9 | import BabiliPlugin from 'babili-webpack-plugin';
|
10 |
|
11 | const isProd = (process.env.ENV === 'production') || (process.env.NODE_ENV === 'production');
|
12 | const isDev = !isProd;
|
13 |
|
14 | const libraryName = 'messenger';
|
15 | const outputFile = isProd ? libraryName + '.min.js' : libraryName + '.js';
|
16 | const outputPath = path.join(__dirname, 'lib');
|
17 | const publicPath = path.join(__dirname, 'examples');
|
18 |
|
19 | webpackConfig = {
|
20 | entry: path.join(__dirname, 'index.js'),
|
21 | stats: {
|
22 | warnings: false,
|
23 | silent: true
|
24 | },
|
25 | output: {
|
26 | path: outputPath,
|
27 | filename: outputFile,
|
28 | library: libraryName,
|
29 | libraryTarget: 'umd',
|
30 | umdNamedDefine: true
|
31 | },
|
32 | module: {
|
33 | rules: [
|
34 | {test: /(\.jsx|\.js)$/, loaders: ['babel-loader', 'eslint-loader'], exclude: /(node_modules)/}
|
35 | ]
|
36 | },
|
37 | plugins: [
|
38 | new ProgressBarPlugin({
|
39 | format: chalk.yellow.bold('Building [:bar] ') + chalk.green.bold(':percent') + chalk.bold(' (:elapsed seconds)'),
|
40 | clear: true,
|
41 | summary: true
|
42 | }),
|
43 | new BuildNotifierPlugin({
|
44 | title: 'CD Messenger',
|
45 | logo: path.resolve(__dirname, 'src/assets/cd-logo.png'),
|
46 | suppressSuccess: true
|
47 | }),
|
48 | new HtmlWebpackPlugin({
|
49 | template: path.join(__dirname,'src/index.ejs'),
|
50 | inject: false,
|
51 | title: 'CD Messenger',
|
52 | script: outputFile
|
53 | })
|
54 | ]
|
55 |
|
56 | };
|
57 |
|
58 | if (isDev) {
|
59 | webpackConfig.devtool = 'source-map';
|
60 | webpackConfig.plugins.push(new WebpackShellPlugin({
|
61 | onBuildStart: ['./node_modules/.bin/bump prerelease'],
|
62 | onBuildExit: []
|
63 | }));
|
64 | }
|
65 |
|
66 | if (isProd) {
|
67 | webpackConfig.plugins.push(new BabiliPlugin({}));
|
68 | }
|
69 |
|
70 | export default webpackConfig;
|