1 | const HtmlWebpackPlugin = require('html-webpack-plugin');
|
2 | const FileManagerPlugin = require('filemanager-webpack-plugin');
|
3 | const webpack = require('webpack');
|
4 | const CompressionPlugin = require('compression-webpack-plugin');
|
5 | const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
|
6 | const { DuplicatesPlugin } = require('inspectpack/plugin');
|
7 | const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
8 | const path = require('path');
|
9 | const VERSION = JSON.stringify(require('./package.json').version).replace(/"/g, '');
|
10 |
|
11 | const BANNER = `RapiPdf ${VERSION.replace()} - WebComponent to generate PDF from OpenAPI spec
|
12 | License: MIT
|
13 | Repo : https://github.com/mrin9/RapiPdf
|
14 | Author : Mrinmoy Majumdar`;
|
15 |
|
16 | const commonPlugins = [
|
17 | new webpack.HotModuleReplacementPlugin(),
|
18 | new webpack.optimize.LimitChunkCountPlugin({
|
19 | maxChunks: 1,
|
20 | }),
|
21 | new HtmlWebpackPlugin({ template: 'index.html' }),
|
22 | new CleanWebpackPlugin(),
|
23 | new webpack.BannerPlugin(BANNER),
|
24 | new webpack.DefinePlugin({ VERSION }),
|
25 | new CompressionPlugin(),
|
26 | new FileManagerPlugin({
|
27 | onEnd: {
|
28 | copy: [
|
29 | { source: 'dist/*.js', destination: 'docs' },
|
30 | ],
|
31 | },
|
32 | }),
|
33 | ];
|
34 |
|
35 | if (process.env.NODE_ENV === 'production') {
|
36 | console.log('BUILDING FOR PRODUCTION ... ');
|
37 | commonPlugins.push(new BundleAnalyzerPlugin({ analyzerMode: 'static' }));
|
38 | commonPlugins.push(new DuplicatesPlugin({ emitErrors: false, verbose: true }));
|
39 | }
|
40 |
|
41 |
|
42 | module.exports = {
|
43 | entry: './src/index.js',
|
44 | node: { fs: 'empty' },
|
45 | externals: {
|
46 | esprima: 'esprima',
|
47 | commander: 'commander',
|
48 | 'native-promise-only': 'native-promise-only',
|
49 | yargs: 'yargs',
|
50 | 'node-fetch': 'null',
|
51 | 'node-fetch-h2': 'null',
|
52 | 'cross-fetch': 'null',
|
53 | qs: 'null',
|
54 | },
|
55 | optimization: {
|
56 | splitChunks: {
|
57 | chunks: 'all',
|
58 | },
|
59 | },
|
60 | devtool: 'cheap-module-source-map',
|
61 | output: {
|
62 | path: path.join(__dirname, 'dist'),
|
63 | filename: 'rapipdf-min.js',
|
64 | },
|
65 | devServer: {
|
66 | contentBase: path.join(__dirname, 'docs'),
|
67 | port: 8080,
|
68 | hot: true,
|
69 | },
|
70 | module: {
|
71 | rules: [
|
72 | {
|
73 | enforce: 'pre',
|
74 | test: /\.js$/,
|
75 | exclude: /node_modules|vfs_fonts.js/,
|
76 | loader: 'eslint-loader',
|
77 | options: {
|
78 | emitWarning: true,
|
79 |
|
80 |
|
81 | fix: true,
|
82 | configFile: './.eslintrc',
|
83 | outputReport: {
|
84 | filePath: './eslint_report.html',
|
85 | formatter: 'html',
|
86 | },
|
87 | },
|
88 | },
|
89 | {
|
90 | test: /\.js$/,
|
91 | exclude: /node_modules|vfs_fonts.js/,
|
92 | loader: 'babel-loader',
|
93 | },
|
94 | {
|
95 | test: /\.css$/,
|
96 | use: [
|
97 | { loader: 'style-loader' },
|
98 | { loader: 'css-loader' },
|
99 | ],
|
100 | },
|
101 | {
|
102 | test: /\.(woff|woff2|eot|ttf|otf)$/,
|
103 | use: [{
|
104 | loader: 'file-loader',
|
105 | options: {
|
106 | name: '[name].[ext]',
|
107 | },
|
108 | }],
|
109 | },
|
110 | ],
|
111 | },
|
112 | resolve: {
|
113 | alias: {
|
114 | '@': path.resolve(__dirname, 'src'),
|
115 | },
|
116 | },
|
117 | plugins: commonPlugins,
|
118 | };
|