UNPKG

3.1 kBJavaScriptView Raw
1/**
2 * Webpack configuration for building bundles
3 */
4const webpack = require('webpack');
5const merge = require('webpack-merge');
6const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
7const FileManagerPlugin = require('filemanager-webpack-plugin');
8const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
9const cssProcessor = require('cssnano');
10const { BUNDLE_NAME, IS_PROD, IS_POS } = require('./helpers/consts.js');
11const MambaManifestPlugin = require('./plugins/MambaManifestPlugin.js');
12const { getPkg } = require('quickenv');
13
14const PKG = getPkg();
15
16module.exports = merge(require('./config.app.js'), {
17 devtool: false,
18 plugins: [
19 IS_POS && new MambaManifestPlugin(),
20 new FileManagerPlugin({
21 onStart: {
22 delete: [
23 `./dist/${BUNDLE_NAME}`,
24 `./dist/${BUNDLE_NAME}.tar.gz`,
25 `./dist/${BUNDLE_NAME}.ppk`,
26 ],
27 },
28 onEnd: {
29 copy: [
30 {
31 source: './src/assets',
32 destination: `./dist/${BUNDLE_NAME}/assets`,
33 },
34 ],
35 archive: [
36 {
37 source: `./dist/${BUNDLE_NAME}/`,
38 destination: `./dist/${BUNDLE_NAME}.tar.gz`,
39 format: 'tar',
40 options: {
41 gzip: true,
42 gzipOptions: { level: 1 },
43 globOptions: { nomount: true },
44 },
45 },
46 {
47 source: `./dist/${BUNDLE_NAME}/`,
48 destination: `./dist/${PKG.name}_v${PKG.version}.ppk`,
49 format: 'zip',
50 options: {
51 gzip: true,
52 gzipOptions: { level: 1 },
53 globOptions: { nomount: true },
54 },
55 },
56 ],
57 },
58 }),
59 /** Generate hashes based on module's relative path */
60 IS_PROD && new webpack.HashedModuleIdsPlugin(),
61 ].filter(Boolean),
62 optimization: {
63 minimize: IS_PROD,
64 minimizer: [
65 /** Minify the bundle's css */
66 new OptimizeCSSAssetsPlugin({
67 /** Default css processor is 'cssnano' */
68 cssProcessor,
69 cssProcessorOptions: {
70 core: IS_PROD,
71 discardComments: IS_PROD,
72 autoprefixer: false,
73 },
74 }),
75 /** Minify the bundle's js */
76 new UglifyJsPlugin({
77 cache: true, // Enables file caching
78 parallel: true, // Use multiple CPUs if available,
79 sourceMap: true, // Enables sourcemap
80 uglifyOptions: {
81 compress: {
82 reduce_funcs: false,
83 keep_fnames: false,
84 /** Functions that doesn't have side-effects */
85 pure_funcs: [
86 'classCallCheck',
87 '_classCallCheck',
88 '_possibleConstructorReturn',
89 'Object.freeze',
90 'invariant',
91 'warning',
92 ],
93 },
94 mangle: {
95 keep_fnames: false,
96 /** Prevent renaming of `process.env...` */
97 reserved: ['process'],
98 },
99 output: {
100 comments: false,
101 },
102 },
103 }),
104 ],
105 },
106});