forked from azeem/webvs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
95 lines (88 loc) · 2.59 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
var path = require('path');
var webpack = require('webpack');
var fs = require('fs');
var packageJson = require('./package.json');
var UglifyJSPlugin = require('uglifyjs-webpack-plugin');
function commonJsConfig(resourcePackUrl) {
if(!resourcePackUrl) {
resourcePackUrl = 'https://unpkg.com/webvs@' + packageJson.version + '/resources/';
}
return {
target: 'node',
entry: './index.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'webvs.node.js',
libraryTarget: 'commonjs2',
},
resolve: {
extensions: ['.ts', '.js', '.pegjs']
},
module: {
rules: [
{
test: /\.pegjs$/,
loader: 'peggy-loader'
},
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader'
}
]
},
plugins: [
new webpack.DefinePlugin({
RESOURCE_PACK_URL: JSON.stringify(resourcePackUrl),
WEBVS_VERSION: JSON.stringify(packageJson.version)
})
],
devtool: 'inline-cheap-module-source-map',
};
};
function webConfig(devServer, production) {
const config = commonJsConfig(devServer ? '/resources/' : null);
config.target = 'web';
config.output = {
path: path.resolve(__dirname, 'dist'),
filename: '[name].js',
library: 'Webvs',
libraryTarget: 'window',
libraryExport: 'default'
};
if (devServer) {
config.serve = {
dev: {
publicPath: '/dist'
},
};
config.output.publicPath = '/dist';
}
if (production) {
config.entry = {
"webvs": "./index.ts",
"webvs.min": "./index.ts",
};
config.plugins.push(new UglifyJSPlugin({
minimize: true,
include: /\.min\.js$/
}));
} else {
config.entry = {
"webvs": ["./index.ts"]
};
}
return config;
}
var target = process.env.TARGET || 'all';
if(target === 'dev') {
module.exports = webConfig(true);
} else if(target == 'all') {
module.exports = [commonJsConfig(), webConfig(false, true)];
} else if(target === 'web') {
module.exports = webConfig();
} else if(target === 'cjs') {
module.exports = commonJsConfig();
} else {
console.error('Unknown target', target);
}