-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
97 lines (91 loc) · 2.46 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
96
97
const fs = require("fs");
const path = require("path");
const webpack = require("webpack");
const webpackMerge = require("webpack-merge");
const PowerbiUmdPlugin = require("./build/PowerbiUmdPlugin");
const TerserPlugin = require("terser-webpack-plugin");
const libraryName = "Shifu";
/**
* Load the config based on the target ( dev | prod)
* @param {Object} env - Environment variable
*/
const modeConfig = env => require(`./build/webpack.${env.mode}`)(env);
// Common webpack configuration
const common = {
entry: "./src/index.ts",
module: {
rules: [
{
test: /\.ts$/,
use: "babel-loader",
exclude: [/node_modules/, /test/]
},
]
},
resolve: {
extensions: [".ts", ".js"]
},
plugins: [
new DtsBundlePlugin(),
new webpack.ProgressPlugin(),
new PowerbiUmdPlugin(),
],
externals: {},
output: {
library: libraryName,
libraryTarget: "umd",
filename: "index.js",
path: path.resolve(__dirname, "dist")
},
optimization: {
minimizer: [
new TerserPlugin({
terserOptions: {
ecma: undefined,
warnings: false,
parse: {},
compress: {},
mangle: false, // Note `mangle.properties` is `false` by default.
module: false,
output: null,
toplevel: false,
nameCache: null,
ie8: false,
keep_classnames: undefined,
keep_fnames: false,
safari10: false
}
})
]
}
};
module.exports = (mode = "production") => {
return webpackMerge(common, modeConfig(mode));
};
function DtsBundlePlugin() {}
DtsBundlePlugin.prototype.apply = function(compiler) {
compiler.plugin("done", function() {
var dts = require("dts-bundle");
var typeDefPath = path.join(__dirname, "dist/index.d.ts");
dts.bundle({
name: libraryName,
main: typeDefPath,
out: typeDefPath,
removeSource: false,
outputAsModuleFolder: true // to use npm in-package typings
});
/**
* Powerbi does not support import statements yet. Hence, the only way to support types in PowerBi Visual is to
* have the following statement in the type definition file.
*/
const text = "export as namespace Shifu;";
let writeStream = fs.createWriteStream(typeDefPath, {
flags: "a"
});
writeStream.write(text);
writeStream.end(err => {
if (err) console.log(err);
console.log("Type Definition written successfully");
});
});
};