-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.js
73 lines (67 loc) · 2.7 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const path = require('path');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const webpack = require('webpack');
function getConfig(isMiniprogram) {
return {
bail: true,
mode: 'development',
devtool: false,
entry: './index.js',
module: {
rules: [
{
test: /\.js$/,
// exclude: /(node_modules)/,
use: ['babel-loader']
},
]
},
output: {
path: path.resolve(__dirname, 'dist'),
filename: !isMiniprogram ? 'qingstor-sdk.js' : 'qingstor-sdk-miniprogram.js',
libraryTarget: 'umd',
library: !isMiniprogram ? 'qingstor_sdk' : 'qingstor_sdk_miniprogram',
},
plugins: [
new BundleAnalyzerPlugin({
// Can be `server`, `static` or `disabled`.
// In `server` mode analyzer will start HTTP server to show bundle report.
// In `static` mode single HTML file with bundle report will be generated.
// In `disabled` mode you can use this plugin to just generate Webpack Stats JSON file by setting `generateStatsFile` to `true`.
analyzerMode: isMiniprogram ? 'disabled' : 'static',
// Host that will be used in `server` mode to start HTTP server.
analyzerHost: '127.0.0.1',
// Port that will be used in `server` mode to start HTTP server.
analyzerPort: 8888,
// Path to bundle report file that will be generated in `static` mode.
// Relative to bundles output directory.
reportFilename: 'report.html',
// Module sizes to show in report by default.
// Should be one of `stat`, `parsed` or `gzip`.
// See "Definitions" section for more information.
defaultSizes: 'parsed',
// Automatically open report in default browser
openAnalyzer: false,
// If `true`, Webpack Stats JSON file will be generated in bundles output directory
generateStatsFile: false,
// Name of Webpack Stats JSON file that will be generated if `generateStatsFile` is `true`.
// Relative to bundles output directory.
statsFilename: 'stats.json',
// Options for `stats.toJson()` method.
// For example you can exclude sources of your modules from stats file with `source: false` option.
// See more options here: https://github.com/webpack/webpack/blob/webpack-1/lib/Stats.js#L21
statsOptions: null,
// Log level. Can be 'info', 'warn', 'error' or 'silent'.
logLevel: 'info'
}),
new webpack.DefinePlugin({
'process.env.MINIPROGRAM': JSON.stringify(isMiniprogram),
}),
],
node: {
fs: 'empty',
process: 'mock'
},
};
}
module.exports = [getConfig(false), getConfig(true)];