-
Notifications
You must be signed in to change notification settings - Fork 900
/
webpack.prod.babel.js
65 lines (59 loc) · 1.5 KB
/
webpack.prod.babel.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
/* eslint-disable import/no-extraneous-dependencies */
// Copyright (c) 2018 ml5
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
import merge from "webpack-merge";
import { resolve } from "path";
import UglifyJSPlugin from "uglifyjs-webpack-plugin";
import CopyPlugin from "copy-webpack-plugin";
import common, { indexEntryWithBabel, developmentPort } from "./webpack.common.babel";
const regexMatchHTMLFiles = /^[^.]+.html$/;
const replaceML5Reference = (content, path) => {
if (!regexMatchHTMLFiles.test(path)) {
return content;
}
return content
.toString()
.replace(
`http://localhost:${developmentPort}/ml5.js`,
"https://unpkg.com/ml5@latest/dist/ml5.min.js",
);
};
const libraryBuildConfig = merge(common, {
mode: "production",
devtool: "source-map",
entry: {
ml5: indexEntryWithBabel,
"ml5.min": indexEntryWithBabel,
},
output: {
filename: "[name].js",
},
optimization: {
minimize: true,
minimizer: [
new UglifyJSPlugin({
include: /\.min\.js$/,
sourceMap: true,
}),
],
},
});
const exampleBuildConfig = merge(common, {
name: "examples",
mode: "production",
output: {
path: resolve(__dirname, "dist_examples"),
publicPath: "/",
},
plugins: [
new CopyPlugin([
{
from: "examples/",
transform: (content, path) => replaceML5Reference(content, path),
},
]),
],
});
export default [libraryBuildConfig, exampleBuildConfig];