-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
106 lines (98 loc) · 3.83 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
98
99
100
101
102
103
104
105
106
const path = require('path');
const webpack = require('webpack');
const bundleOutputDir = './dist';
const DeclarationBundlerPlugin = require('types-webpack-bundler');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const libraryName = "poker-api-server";
function DtsBundlePlugin() {
}
DtsBundlePlugin.prototype.apply = function (compiler) {
// compiler.plugin('done', function () {
// var dts = require('dts-bundle');
// dts.bundle({
// name: libraryName,
// main: 'out/index.d.ts',
// out: '../dist/index.d.ts',
// removeSource: false,
// outputAsModuleFolder: true // to use npm in-package typings
// });
// });
const { webpack } = compiler
const { Compilation } = webpack
const { RawSource } = webpack.sources
compiler.hooks.thisCompilation.tap('DeclarationBundlerPlugin', (compilation) => {
compilation.hooks.processAssets.tap({
name: 'DeclarationBundlerPlugin',
stage: Compilation.PROCESS_ASSETS_STAGE_OPTIMIZE
}, (assets) => {
//collect all generated declaration files
//and remove them from the assets that will be emitted
const declarationFiles = {}
for (const filename in assets) {
if (filename.indexOf('.d.ts') !== -1) {
declarationFiles[filename] = assets[filename]
compilation.deleteAsset(filename)
}
}
//combine them into one declaration file
//const combinedDeclaration = this.generateCombinedDeclaration(declarationFiles)
//and insert that back into the assets
//compilation.emitAsset(this.out, new RawSource(combinedDeclaration))
var dts = require('dts-bundle');
dts.bundle({
name: libraryName,
main: 'out/index.d.ts',
out: '../dist/index.d.ts',
removeSource: false,
outputAsModuleFolder: true // to use npm in-package typings
});
})
});
};
module.exports = (env) => {
const isDevBuild = !(env && env.prod);
return [{
//mode: isDevBuild ? "development" : "production",
stats: { modules: false },
entry: { 'poker-api-server': './src/index' },
resolve: {
extensions: ['.js', '.jsx', '.ts', '.tsx']
},
externals: {
jquery: 'jquery'
},
output: {
path: path.join(__dirname, bundleOutputDir),
filename: '[name].js',
publicPath: 'dist/',
library: {
root: "PokerAPI",
amd: 'poker-api-server',
commonjs: 'poker-api-server',
},
libraryTarget: "umd",
umdNamedDefine: true
},
module: {
rules: [
{ test: /\.(tsx|ts)?$/, include: /src/, use: 'ts-loader' }
]
},
plugins: [
//new ForkTsCheckerWebpackPlugin(),
new DtsBundlePlugin(),
// new DeclarationBundlerPlugin({
// moduleName: libraryName,
// out:'./index.d.ts',
// }),
].concat(isDevBuild ? [
// Plugins that apply in development builds only
new webpack.SourceMapDevToolPlugin({
filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
})
] : [
// Plugins that apply in production builds only
])
}];
};