• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
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
22const { VueLoaderPlugin } = require("vue-loader")
23const HtmlWebpackPlugin = require('html-webpack-plugin');
24const KotlinWebpackPlugin = require('@jetbrains/kotlin-webpack-plugin');
25const HtmlWebpackInlineSourcePlugin =
26  require('html-webpack-inline-source-plugin');
27
28const isDev = process.env.NODE_ENV === 'development';
29
30
31function getWaylandSafePath() {
32  const waylandPath =
33    path.resolve(__dirname, '../../../vendor/google_arc/libs/wayland_service');
34
35  if (fs.existsSync(waylandPath)) {
36    return waylandPath;
37  }
38
39  return path.resolve(__dirname, 'src/stubs');
40}
41
42const webpackConfig = {
43  entry: {
44    polyfill: '@babel/polyfill',
45    main: './src/main.js',
46  },
47  externals: {
48    _: 'lodash',
49  },
50  resolve: {
51    extensions: ['.tsx', '.ts', '.js', '.vue'],
52    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',
60      path.resolve(__dirname, '../../..'),
61    ],
62  },
63  resolveLoader: {
64    modules: [
65      'node_modules',
66      path.resolve(__dirname, 'loaders'),
67    ],
68  },
69  module: {
70    rules: [
71      {
72        test: /\.vue$/,
73        loader: 'vue-loader',
74        include: path.resolve(__dirname, './src'),
75        exclude: /node_modules/,
76      },
77      {
78        test: /\.tsx?$/,
79        use: 'ts-loader',
80        include: path.resolve(__dirname, './src'),
81        exclude: /node_modules/,
82      },
83      {
84        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',
93          {loader: 'css-loader', options: {sourceMap: isDev}},
94        ],
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, '../../..'),
104            path.resolve(__dirname, '../../../external/protobuf/src'),
105          ],
106        },
107      },
108      {
109        test: /\.(png|jpg|gif|svg)$/,
110        loader: 'file-loader',
111        options: {
112          name: '[name].[ext]?[hash]',
113        },
114      },
115      {
116        test: /\.(ttf|otf|eot|woff|woff2)$/,
117        use: {
118          loader: 'file-loader',
119          options: {
120            name: 'fonts/[name].[ext]',
121          },
122        },
123      },
124    ],
125  },
126  plugins: [
127    new VueLoaderPlugin(),
128    new HtmlWebpackPlugin({
129      inlineSource: isDev ? false : '.(js|css)',
130      template: 'src/index_template.html',
131    }),
132    new HtmlWebpackInlineSourcePlugin(HtmlWebpackPlugin),
133    new KotlinWebpackPlugin({
134      src: [
135        path.join(__dirname, '../../../platform_testing/libraries/flicker/' +
136          'src/com/android/server/wm/traces/common/'),
137      ],
138      output: 'kotlin_build',
139      moduleName: 'flicker',
140      librariesAutoLookup: true,
141      sourceMaps: true,
142      sourceMapEmbedSources: 'always',
143      verbose: true,
144      optimize: true,
145    }),
146  ],
147};
148
149module.exports = webpackConfig;
150