blob: 2806bd9db28935f77a9b852cabf6a0daa1e3214f [file] [log] [blame]
Idan Amita2c544d2018-07-19 12:05:50 +03001var path = require("path");
2var webpack = require("webpack");
3var UglifyJsPlugin = require("uglifyjs-webpack-plugin");
4
5var PATHS = {
Idan Amitbbeb5902019-01-03 18:18:37 +02006 entryPoint: path.resolve(__dirname, './index.ts'),
Idan Amita2c544d2018-07-19 12:05:50 +03007 bundles: path.resolve(__dirname, 'dist'),
Idan Amitbbeb5902019-01-03 18:18:37 +02008};
Idan Amita2c544d2018-07-19 12:05:50 +03009
10var config = {
11 // These are the entry point of our library. We tell webpack to use
12 // the name we assign later, when creating the bundle. We also use
13 // the name to filter the second entry point for applying code
14 // minification via UglifyJS
15 entry: {
Idan Amitbbeb5902019-01-03 18:18:37 +020016 'sdc-pubsub': PATHS.entryPoint,
17 'sdc-pubsub.min': PATHS.entryPoint
Idan Amita2c544d2018-07-19 12:05:50 +030018 },
19 // The output defines how and where we want the bundles. The special
20 // value `[name]` in `filename` tell Webpack to use the name we defined above.
21 // We target a UMD and name it MyLib. When including the bundle in the browser
22 // it will be accessible at `window.MyLib`
23 output: {
24 path: PATHS.bundles,
25 filename: '[name].js',
26 libraryTarget: 'umd',
27 library: 'sdcPubSub',
28 umdNamedDefine: true
29 },
30 // Add resolve for `tsx` and `ts` files, otherwise Webpack would
31 // only look for common JavaScript file extension (.js)
32 resolve: {
33 extensions: ['.ts', '.js']
34 },
35 // Activate source maps for the bundles in order to preserve the original
36 // source when the user debugs the application
37 devtool: 'source-map',
38 plugins: [
39 // Apply minification only on the second bundle by
40 // using a RegEx on the name, which must end with `.min.js`
41 // NB: Remember to activate sourceMaps in UglifyJsPlugin
42 // since they are disabled by default!
43 new UglifyJsPlugin({
44 sourceMap: true,
45 include: /\.min\.js$/,
46 })
47 ],
48 module: {
49 // Webpack doesn't understand TypeScript files and a loader is needed.
50 // `node_modules` folder is excluded in order to prevent problems with
51 // the library dependencies, as well as `__tests__` folders that
52 // contain the tests for the library
53 rules: [
54 {
55 test: /\.ts?$/,
56 use: [
57 {
Idan Amitbbeb5902019-01-03 18:18:37 +020058 loader: 'ts-loader',
Idan Amita2c544d2018-07-19 12:05:50 +030059 options: {
Idan Amitbbeb5902019-01-03 18:18:37 +020060 configFile: 'tsconfig.json'
Idan Amita2c544d2018-07-19 12:05:50 +030061 }
62 }
63 ]
64 }]
65 }
Idan Amitbbeb5902019-01-03 18:18:37 +020066};
Idan Amita2c544d2018-07-19 12:05:50 +030067
68module.exports = config;