-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebpack.config.js
More file actions
78 lines (66 loc) · 1.62 KB
/
webpack.config.js
File metadata and controls
78 lines (66 loc) · 1.62 KB
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
// 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 = 'posjs.min.js'
} else {
outdir = "lib"
filename = 'posjs.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/posjs.js"),
output: {
path: path.resolve( __dirname, outdir),
filename: filename,
},
resolve: {
extensions: ['.js']
},
devtool: isProd ? false : '#eval-source-map',
plugins: xplugins,
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader'],
}
]
}
}
config.plugins.push(new CleanWebpackPlugin());
if (isWeb) {
config['target'] = 'web'
config['output']['library'] = "posjs"
config['output']['libraryTarget'] = "umd"
config['output']['umdNamedDefine'] = true
} else {
config['target'] = 'node'
config['node'] = {
__dirname: true,
__filename: true
}
config['output']['library'] = "posjs"
config['output']['libraryTarget'] = "commonjs2"
}
return config;
};