-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
95 lines (88 loc) · 2.45 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
"use strict";
const webpack = require('webpack');
const replace = require('replace-in-file');
const fs = require('fs');
const path = require('path');
const pkg = require('./package.json');
const Case = require('case');
const name = Case.kebab(pkg.name);
const date = new Date().toISOString().slice(0, 10);
const author = pkg.author.slice(0, pkg.author.indexOf(' <'));
const banner = `${name} ${pkg.version} by ${author} ${date}
${pkg.homepage}
License ${pkg.license}`;
var postBuildTasks = {
apply: function(compiler) {
compiler.plugin('after-emit', function(compiler, callback) {
var matterToolsPath = path.dirname(require.resolve('matter-tools')) + '/build/matter-tools.demo.js';
// replace constants
replace.sync({
files: ['index.js', 'docs/examples/*.js', 'docs/index.html'],
replace: [
/(['"])(.*)(['"][;,\s]*\/\/\s*PLUGIN_NAME)/g,
/(['"])(.*)(['"][;,\s]*\/\/\s*PLUGIN_VERSION)/g,
/(['"])(.*)(['"][;,\s]*\/\/\s*PLUGIN_REPO_URL)/g
],
with: [
"$1" + name + "$3",
"$1" + pkg.version + "$3",
"$1" + pkg.repository.url.replace('.git', '') + "$3"
]
});
// copy libs to demo
copySync(require.resolve('matter-js'), 'docs/libs/matter.js');
copySync(matterToolsPath, 'docs/libs/matter-tools.demo.js');
copySync('build/' + name + '.js', 'docs/libs/bundle.js');
// done
callback();
});
}
};
var copySync = function(src, dest) {
fs.writeFileSync(dest, fs.readFileSync(src));
console.info('copied', path.basename(dest));
};
module.exports = {
entry: {
[name]: `./src/${name}.js`,
[name + '.min']: `./src/${name}.js`
},
output: {
library: Case.pascal(name),
path: path.resolve(__dirname, './build'),
publicPath: '/libs',
filename: '[name].js',
libraryTarget: 'umd'
},
externals: {
'matter-js': {
commonjs: 'matter-js',
commonjs2: 'matter-js',
amd: 'matter-js',
root: 'Matter'
}
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
include: /\.min\.js$/,
minimize: true
}),
new webpack.BannerPlugin(banner),
postBuildTasks
],
devServer: {
proxy: {
'/libs/bundle.js': {
target: 'http://localhost:8080/',
pathRewrite: { '^/libs/bundle\\.js' : '/libs/' + name + '.js' }
}
}
}
};