blob: 12b44a07ac6cb2b9b32c7b9c6b0b87a87aae8c50 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001/* Copyright 2019 The Chromium Authors. All Rights Reserved.
2 *
3 * Use of this source code is governed by a BSD-style
4 * license that can be found in the LICENSE file.
5 */
6
7const path = require('path');
8const webpack = require('webpack');
9const BundleAnalyzerPlugin =
10 require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
11const HtmlWebpackPlugin = require('html-webpack-plugin');
Copybara854996b2021-09-07 19:36:02 +000012const CircularDependencyPlugin = require('circular-dependency-plugin');
13
14const config = {
15 entry: {
16 'mr-app': './static_src/elements/mr-app/mr-app.js',
17 'mr-profile-page':
18 './static_src/elements/chdir/mr-profile-page/mr-profile-page.js',
19 'ezt-element-package': './static_src/elements/ezt/ezt-element-package.js',
20 'ezt-footer-scripts-package':
21 './static_src/elements/ezt/ezt-footer-scripts-package.js',
22 },
23 devtool: 'eval-source-map',
24 plugins: [
25 new CircularDependencyPlugin({
26 // exclude detection of files based on a RegExp
27 exclude: /a\.js|node_modules/,
28 // add errors to webpack instead of warnings
29 failOnError: true,
30 // set the current working directory for displaying module paths
31 cwd: process.cwd(),
32 }),
33 new HtmlWebpackPlugin({
34 chunks: ['mr-app'],
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020035 inject: false,
Copybara854996b2021-09-07 19:36:02 +000036 template: 'static_src/webpacked-scripts-template.html',
37 filename: '../../templates/webpack-out/mr-app.ezt',
38 }),
39 new HtmlWebpackPlugin({
40 chunks: ['mr-profile-page'],
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020041 inject: false,
Copybara854996b2021-09-07 19:36:02 +000042 template: 'static_src/webpacked-scripts-template.html',
43 filename: '../../templates/webpack-out/mr-profile-page.ezt',
44 }),
45 new HtmlWebpackPlugin({
46 chunks: ['ezt-element-package'],
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020047 inject: false,
Copybara854996b2021-09-07 19:36:02 +000048 template: 'static_src/webpacked-scripts-template.html',
49 filename: '../../templates/webpack-out/ezt-element-package.ezt',
50 }),
51 new HtmlWebpackPlugin({
52 chunks: ['ezt-footer-scripts-package'],
Adrià Vilanova Martínezac4a6442022-05-15 19:05:13 +020053 inject: false,
Copybara854996b2021-09-07 19:36:02 +000054 template: 'static_src/webpacked-scripts-template.html',
55 filename: '../../templates/webpack-out/ezt-footer-scripts-package.ezt',
56 }),
Copybara854996b2021-09-07 19:36:02 +000057 ],
58 module: {
59 rules: [
60 {
61 test: /\.(ts|tsx)$/,
62 exclude: /node_modules/,
63 use: ['babel-loader'],
64 },
65 {
66 test: /\.css$/i,
67 use: [
68 {loader: 'style-loader', options: {injectType: 'styleTag'}},
69 {
70 loader: 'css-loader',
71 options: {
72 modules: true,
73 importLoaders: 1,
74 },
75 },
76 'postcss-loader',
77 ],
78 },
79 ],
80 },
81 resolve: {
82 extensions: ['.js', '.ts', '.tsx'],
83 modules: ['node_modules', 'static_src'],
84 },
85 output: {
86 filename: '[name].[contenthash].min.js',
87 path: path.resolve(__dirname, 'static/dist'),
88 // __webpack_public_path__ is used to dynamically set the public path to
89 // the App Engine version URL.
90 publicPath: '/static/dist/',
91 },
92 externals: {
93 moment: 'moment',
94 },
95};
96
97module.exports = (env, argv) => {
98 if (argv.mode === 'production') {
99 // Settings for deploying JS to production.
100 config.devtool = 'source-map';
101
102 config.plugins = config.plugins.concat([
103 new webpack.DefinePlugin(
104 {'process.env.NODE_ENV': '"production"'},
105 ),
106 ]);
107 }
108
109 if (argv.analyze) {
110 config.plugins.push(new BundleAnalyzerPlugin());
111 }
112 return config;
113};