-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
93 lines (77 loc) · 2.02 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
// webpack.config.js
var webpack = require('webpack')
var path = require('path');
var {CleanWebpackPlugin} = require('clean-webpack-plugin');
//var UglifyJsPlugin = require('uglifyjs-webpack-plugin');
var assign = require('object-assign');
module.exports = function (options) {
console.log(options)
let isProd = options.production == 'prod'
let isWeb = options.web == 'web'
let outdir, filename;
if (isWeb) {
outdir = "dist"
filename = 'skyvaultjs.min.js'
} else {
outdir = "lib"
filename = 'skyvaultjs.js'
}
let xplugins
if (isProd) {
xplugins = [new webpack.DefinePlugin({'process.env': {'NODE_ENV': '"production"'}})]
// if (isWeb) {
// xplugins.push(new UglifyJsPlugin())
// }
} else {
xplugins = [new webpack.DefinePlugin({'process.env': {'NODE_ENV': '"development"'}})]
}
let config = {
context: __dirname,
entry: path.join(__dirname, "src/skyvaultjs.js"),
output: {
path: path.resolve(__dirname, outdir),
filename: filename,
},
resolve: {
extensions: ['.js']
},
devtool: 'eval-source-map',
plugins: xplugins,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader'],
}
]
}
}
if (!isWeb) {
config.externals = {canvas: {}}
}
config.plugins.push(new webpack.ProvidePlugin({process: 'process/browser'}));
config.plugins.push(new CleanWebpackPlugin());
if (isWeb) {
config['target'] = 'web'
config['output']['library'] = "skyvaultjs"
config['output']['libraryTarget'] = "umd"
config['output']['umdNamedDefine'] = true
} else {
config['target'] = 'node'
config['node'] = {
__dirname: true,
__filename: true
}
config['output']['library'] = "skyvaultjs"
config['output']['libraryTarget'] = "commonjs2"
}
config['devServer'] = {
static: {
directory: path.join(__dirname, 'public'),
},
compress: true,
port: 9000,
}
return config;
};