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