blob: 48d950a51cc4458a2117c566f5391744589b081a [file] [log] [blame]
Pablo Gamito3f239132020-07-17 12:33:32 +01001/*
2 * Copyright 2020, The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17'use strict';
18
19const path = require('path');
20const fs = require('fs');
21
Nataniel Borgesafdaa0e2021-07-13 18:47:19 +020022const { VueLoaderPlugin } = require("vue-loader")
Pablo Gamito3f239132020-07-17 12:33:32 +010023const HtmlWebpackPlugin = require('html-webpack-plugin');
24const KotlinWebpackPlugin = require('@jetbrains/kotlin-webpack-plugin');
Pablo Gamito9d56e692020-09-02 13:04:28 +020025const HtmlWebpackInlineSourcePlugin =
26 require('html-webpack-inline-source-plugin');
Pablo Gamito3f239132020-07-17 12:33:32 +010027
28const isDev = process.env.NODE_ENV === 'development';
29
30
31function getWaylandSafePath() {
Pablo Gamito9d56e692020-09-02 13:04:28 +020032 const waylandPath =
33 path.resolve(__dirname, '../../../vendor/google_arc/libs/wayland_service');
Pablo Gamito1ca3eda2020-09-02 17:59:52 +020034
Pablo Gamito3f239132020-07-17 12:33:32 +010035 if (fs.existsSync(waylandPath)) {
36 return waylandPath;
37 }
Pablo Gamito1ca3eda2020-09-02 17:59:52 +020038
Pablo Gamito3f239132020-07-17 12:33:32 +010039 return path.resolve(__dirname, 'src/stubs');
40}
41
42const webpackConfig = {
43 entry: {
44 polyfill: '@babel/polyfill',
45 main: './src/main.js',
46 },
Pablo Gamito335b3e12020-07-17 12:36:18 +010047 externals: {
48 _: 'lodash',
49 },
Pablo Gamito3f239132020-07-17 12:33:32 +010050 resolve: {
Pablo Gamito1ca3eda2020-09-02 17:59:52 +020051 extensions: ['.tsx', '.ts', '.js', '.vue'],
Pablo Gamito3f239132020-07-17 12:33:32 +010052 alias: {
53 'vue$': isDev ? 'vue/dist/vue.runtime.js' : 'vue/dist/vue.runtime.min.js',
54 '@': path.resolve(__dirname, 'src'),
55 'WaylandSafePath': getWaylandSafePath(),
56 },
57 modules: [
58 'node_modules',
59 'kotlin_build',
Pablo Gamito9d56e692020-09-02 13:04:28 +020060 path.resolve(__dirname, '../../..'),
Pablo Gamito3f239132020-07-17 12:33:32 +010061 ],
62 },
63 resolveLoader: {
64 modules: [
65 'node_modules',
Pablo Gamito9d56e692020-09-02 13:04:28 +020066 path.resolve(__dirname, 'loaders'),
67 ],
Pablo Gamito3f239132020-07-17 12:33:32 +010068 },
69 module: {
70 rules: [
71 {
72 test: /\.vue$/,
73 loader: 'vue-loader',
74 include: path.resolve(__dirname, './src'),
75 exclude: /node_modules/,
76 },
77 {
Pablo Gamito1ca3eda2020-09-02 17:59:52 +020078 test: /\.tsx?$/,
79 use: 'ts-loader',
80 include: path.resolve(__dirname, './src'),
81 exclude: /node_modules/,
82 },
83 {
Pablo Gamito3f239132020-07-17 12:33:32 +010084 test: /\.js$/,
85 loader: 'babel-loader',
86 include: path.resolve(__dirname, './src'),
87 exclude: /node_modules/,
88 },
89 {
90 test: /\.css$/,
91 use: [
92 'vue-style-loader',
Pablo Gamito9d56e692020-09-02 13:04:28 +020093 {loader: 'css-loader', options: {sourceMap: isDev}},
Pablo Gamito3f239132020-07-17 12:33:32 +010094 ],
95 include: path.resolve(__dirname, './src'),
96 exclude: /node_modules/,
97 },
98 {
99 test: /\.proto$/,
100 loader: 'proto-loader',
101 options: {
102 paths: [
103 path.resolve(__dirname, '../../..'),
Pablo Gamito9d56e692020-09-02 13:04:28 +0200104 path.resolve(__dirname, '../../../external/protobuf/src'),
105 ],
106 },
Pablo Gamito3f239132020-07-17 12:33:32 +0100107 },
108 {
109 test: /\.(png|jpg|gif|svg)$/,
110 loader: 'file-loader',
111 options: {
Pablo Gamito9d56e692020-09-02 13:04:28 +0200112 name: '[name].[ext]?[hash]',
113 },
Pablo Gamito3f239132020-07-17 12:33:32 +0100114 },
115 {
116 test: /\.(ttf|otf|eot|woff|woff2)$/,
117 use: {
Pablo Gamito9d56e692020-09-02 13:04:28 +0200118 loader: 'file-loader',
Pablo Gamito3f239132020-07-17 12:33:32 +0100119 options: {
Pablo Gamito9d56e692020-09-02 13:04:28 +0200120 name: 'fonts/[name].[ext]',
Pablo Gamito3f239132020-07-17 12:33:32 +0100121 },
122 },
123 },
Pablo Gamito9d56e692020-09-02 13:04:28 +0200124 ],
Pablo Gamito3f239132020-07-17 12:33:32 +0100125 },
126 plugins: [
127 new VueLoaderPlugin(),
128 new HtmlWebpackPlugin({
129 inlineSource: isDev ? false : '.(js|css)',
Pablo Gamito9d56e692020-09-02 13:04:28 +0200130 template: 'src/index_template.html',
Pablo Gamito3f239132020-07-17 12:33:32 +0100131 }),
Nataniel Borgesafdaa0e2021-07-13 18:47:19 +0200132 new HtmlWebpackInlineSourcePlugin(HtmlWebpackPlugin),
Pablo Gamito3f239132020-07-17 12:33:32 +0100133 new KotlinWebpackPlugin({
134 src: [
Pablo Gamito9d56e692020-09-02 13:04:28 +0200135 path.join(__dirname, '../../../platform_testing/libraries/flicker/' +
Nataniel Borges95347472020-10-23 14:22:19 +0200136 'src/com/android/server/wm/traces/common/'),
Pablo Gamito3f239132020-07-17 12:33:32 +0100137 ],
138 output: 'kotlin_build',
139 moduleName: 'flicker',
140 librariesAutoLookup: true,
141 sourceMaps: true,
142 sourceMapEmbedSources: 'always',
143 verbose: true,
144 optimize: true,
145 }),
Pablo Gamito9d56e692020-09-02 13:04:28 +0200146 ],
Pablo Gamito3f239132020-07-17 12:33:32 +0100147};
148
Pablo Gamito9d56e692020-09-02 13:04:28 +0200149module.exports = webpackConfig;