blob: 73c10dd5d0cf3c8c8b4a2c7a491f85b501a926c1 [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 = {
6 entryPoint: path.resolve(__dirname, 'index.ts'),
7 bundles: path.resolve(__dirname, 'dist'),
8}
9
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: {
16 'sdc-pubsub': [PATHS.entryPoint],
17 'sdc-pubsub.min': [PATHS.entryPoint]
18 },
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 {
58 loader: 'awesome-typescript-loader',
59 options: {
60 configFileName: 'tsconfig.json'
61 }
62 }
63 ]
64 }]
65 }
66}
67
68module.exports = config;