forked from alibaba/butterfly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
92 lines (88 loc) · 2.12 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const _ = require('lodash');
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const common = {
mode: 'production',
devtool: 'cheap-module-source-map',
performance: {
hints: false
},
entry: './index.js',
target: ['web', 'es5'],
output: {
path: __dirname,
filename: 'dist/index.js',
libraryTarget: 'umd',
environment: {
arrowFunction: false
}
},
resolve: {
alias: {},
},
plugins: [
new MiniCssExtractPlugin({
filename: 'dist/index.css',
chunkFilename: '[id].css'
})
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'], //'env'--babel7中的es7语法编译插件
// plugins: ['transform-decorators-legacy', 'transform-class-properties', 'add-module-exports', 'transform-object-rest-spread'],
plugins: ['transform-es2015-modules-commonjs', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-proposal-class-properties']
}
}
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
{
loader: "css-loader" // translates CSS into CommonJS
},
{
loader: "less-loader" // compiles Less to CSS
}
]
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 1024 * 200,
name: '[name].[ext]',
outputPath: '/dist/fonts/'
}
}
}
]
},
optimization: {
minimize: false
}
};
const main = _.cloneDeep(common);
const unpkg = _.cloneDeep(common);
/**
* unpkg包需要满足条件:
* 1. no sourcemap
* 2. no mini-css-extract-plugin
* 3. minimize: true
*/
unpkg.optimization.minimize = true;
delete unpkg.devtool;
unpkg.output.filename = 'unpkg/index.unpkg.js';
unpkg.plugins.pop();
unpkg.module.rules[1].use.shift();
module.exports = [
main,
unpkg
];