forked from ml5js/ml5-library
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.prod.babel.js
59 lines (53 loc) · 1.41 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
// 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 common, {indexEntryWithBabel, developmentPort} from './webpack.common.babel';
import UglifyJSPlugin from 'uglifyjs-webpack-plugin';
import CopyPlugin from 'copy-webpack-plugin';
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];