-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
115 lines (99 loc) · 2.53 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
const path = require('path');
const TerserPlugin = require('terser-webpack-plugin');
const CopyPlugin = require("copy-webpack-plugin");
const webpack = require('webpack');
const pkg = require('./package.json');
const env = process.env.NODE_ENV;
module.exports = function (env, argv) {
let builddir = argv.mode== 'production' ? 'docs' : 'test';
let baseConf = {
watch: argv.mode != 'production',
target: 'web',
optimization: {
minimizer: [new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
}})]
},
mode: argv.mode,
entry: {
"demo": './src/demo.js',
"baremde_web":{import: './src/baremde_web' },
},
devtool: argv.mode != "production" ? 'inline-source-map' : false,
devServer: argv.mode != "production" ? {contentBase: 'docs'} : {contentBase: 'test'},
output: {
path: path.resolve(__dirname, builddir, "")
},
module: {
rules: [
{
test: /\.svg$/,
resourceQuery: /raw/,
type: 'asset/source'
},
{
test: /\.svg$/,
resourceQuery: { not: [/raw/] },
type: 'asset/inline'
},
{
test: /\.(less|css|scss)$/,
use: [
'style-loader' ,
'css-loader',
'sass-loader'
],
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: "babel-loader"
}
}
]
},
plugins: [
new CopyPlugin({
patterns: [
{ from: "src/demo_html/*.*" , to( {context , absoluteFilename} ){
return "[name][ext]"
} },
],
}),
new webpack.DefinePlugin({
// Definitions...
'VERSION': JSON.stringify(pkg.version)
}),
],
};
let libConf = Object.assign({} , baseConf);
// build the lib
libConf.entry = {
"BareMDE": {
import: './src/components/BareMDE/index.js',
library: {
type: "umd",
name: "BareMDE",
}
},
};
libConf.externalsType="umd";
//do not bundle preact to the lib
libConf.externals = 'preact';
libConf.plugins = [
new webpack.DefinePlugin({
'VERSION': JSON.stringify(pkg.version)
}),
];
//do not need to output it to 'test'
libConf.output= {
path: path.resolve(__dirname, "dist", ""),
filename: "BareMDE_v"+pkg.version+ ".umd.js"
};
return [ baseConf , libConf ] ;
}