1 | const path = require('path');
|
2 | const webpack = require('webpack');
|
3 | const { existsSync } = require('fs');
|
4 | const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
5 | const DuplicatePackageCheckerPlugin = require('duplicate-package-checker-webpack-plugin');
|
6 | const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
|
7 | const loaders = require('@availity/workflow-settings/webpack');
|
8 |
|
9 | process.noDeprecation = true;
|
10 |
|
11 | const plugin = settings => {
|
12 | const babelrcPath = path.join(settings.project(), '.babelrc');
|
13 | const babelrcExists = existsSync(babelrcPath);
|
14 |
|
15 | function getVersion() {
|
16 | return settings.pkg().version || 'N/A';
|
17 | }
|
18 |
|
19 | const config = {
|
20 | context: settings.app(),
|
21 |
|
22 | optimization: {
|
23 | splitChunks: {
|
24 | cacheGroups: {
|
25 | styles: {
|
26 | name: 'styles',
|
27 | test: /\.css$/,
|
28 | chunks: 'all',
|
29 | enforce: true
|
30 | },
|
31 | commons: {
|
32 | chunks: 'initial',
|
33 | minChunks: 2
|
34 | },
|
35 | vendor: {
|
36 | test: /node_modules/,
|
37 | chunks: 'initial',
|
38 | name: 'vendor',
|
39 | priority: 10,
|
40 | enforce: true
|
41 | }
|
42 | }
|
43 | },
|
44 | minimizer: []
|
45 | },
|
46 |
|
47 | entry: {
|
48 | index: ['./index.js']
|
49 | },
|
50 |
|
51 | output: {
|
52 | path: settings.output(),
|
53 | filename: settings.fileName()
|
54 | },
|
55 |
|
56 | devtool: 'cheap-module-source-map',
|
57 |
|
58 | resolve: {
|
59 |
|
60 | modules: [
|
61 | settings.app(),
|
62 | 'node_modules',
|
63 | path.join(settings.project(), 'node_modules'),
|
64 | path.join(__dirname, 'node_modules')
|
65 | ],
|
66 | symlinks: true,
|
67 | extensions: ['.js', '.jsx', '.json', '.css', 'scss']
|
68 | },
|
69 |
|
70 |
|
71 |
|
72 | resolveLoader: {
|
73 | modules: [path.join(settings.project(), 'node_modules'), path.join(__dirname, 'node_modules')],
|
74 | symlinks: true
|
75 | },
|
76 |
|
77 | module: {
|
78 | rules: [
|
79 | {
|
80 | test: /\.jsx?$/,
|
81 | include: settings.include(),
|
82 | use: [
|
83 | {
|
84 | loader: 'babel-loader',
|
85 | options: {
|
86 | presets: [require.resolve('@availity/workflow-babel-preset')],
|
87 | cacheDirectory: settings.isDevelopment(),
|
88 | babelrc: babelrcExists
|
89 | }
|
90 | }
|
91 | ]
|
92 | },
|
93 |
|
94 | loaders.css.production,
|
95 | loaders.scss.production,
|
96 | loaders.fonts,
|
97 | loaders.images
|
98 | ]
|
99 | },
|
100 | plugins: [
|
101 | new webpack.DefinePlugin(settings.globals('')),
|
102 |
|
103 | new webpack.BannerPlugin({
|
104 | banner: `APP_VERSION=${JSON.stringify(getVersion())};`,
|
105 | test: /\.jsx?/,
|
106 | raw: true,
|
107 | entryOnly: true
|
108 | }),
|
109 |
|
110 | new webpack.BannerPlugin({
|
111 | banner: `v${getVersion()} - ${new Date().toJSON()}`
|
112 | }),
|
113 |
|
114 | new BundleAnalyzerPlugin({
|
115 | analyzerMode: 'static',
|
116 | reportFilename: 'profile.html'
|
117 | }),
|
118 |
|
119 | new loaders.MiniCssExtractPlugin({
|
120 | filename: 'css/[name]-[contenthash].css'
|
121 | }),
|
122 |
|
123 | new DuplicatePackageCheckerPlugin({
|
124 | exclude(instance) {
|
125 | return instance.name === 'regenerator-runtime';
|
126 | }
|
127 | }),
|
128 |
|
129 |
|
130 | new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
131 |
|
132 | new CaseSensitivePathsPlugin(),
|
133 |
|
134 | new webpack.ProvidePlugin({
|
135 | Promise: 'es6-promise-promise',
|
136 | Symbol: 'es6-symbol'
|
137 | })
|
138 | ]
|
139 | };
|
140 |
|
141 | return config;
|
142 | };
|
143 |
|
144 | module.exports = plugin;
|