UNPKG

2.05 kBJavaScriptView Raw
1import webpack from 'webpack';
2import path from 'path';
3import chalk from 'chalk';
4
5import BuildNotifierPlugin from 'webpack-build-notifier';
6import HtmlWebpackPlugin from 'html-webpack-plugin';
7import ProgressBarPlugin from 'progress-bar-webpack-plugin';
8import WebpackShellPlugin from '@slightlytyler/webpack-shell-plugin';
9import BabiliPlugin from 'babili-webpack-plugin';
10
11const isProd = (process.env.ENV === 'production') || (process.env.NODE_ENV === 'production');
12const isDev = !isProd;
13
14const libraryName = 'messenger';
15const outputFile = isProd ? libraryName + '.min.js' : libraryName + '.js';
16const outputPath = path.join(__dirname, 'lib');
17const publicPath = path.join(__dirname, 'examples');
18
19webpackConfig = {
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
58if (isDev) {
59 webpackConfig.devtool = 'source-map';
60 webpackConfig.plugins.push(new WebpackShellPlugin({
61 onBuildStart: ['./node_modules/.bin/bump prerelease'], // need to bump version first before files copied etc
62 onBuildExit: []
63 }));
64}
65
66if (isProd) {
67 webpackConfig.plugins.push(new BabiliPlugin({}));
68}
69
70export default webpackConfig;