Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017, 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 | |
Vishnu Nair | fe15959 | 2020-05-19 21:44:19 -0700 | [diff] [blame] | 17 | const fs = require('fs'); |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 18 | var path = require('path') |
| 19 | var webpack = require('webpack') |
Adrian Roos | 77d8a39 | 2017-12-29 16:20:58 +0100 | [diff] [blame] | 20 | var HtmlWebpackPlugin = require('html-webpack-plugin') |
| 21 | var HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin') |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 22 | |
Vishnu Nair | 92dccb5 | 2020-01-27 15:00:13 -0800 | [diff] [blame] | 23 | function getWaylandSafePath() { |
Vishnu Nair | fe15959 | 2020-05-19 21:44:19 -0700 | [diff] [blame] | 24 | waylandPath = path.resolve(__dirname, '../../../vendor/google_arc/libs/wayland_service'); |
| 25 | if (fs.existsSync(waylandPath)) { |
| 26 | return waylandPath; |
Vishnu Nair | 92dccb5 | 2020-01-27 15:00:13 -0800 | [diff] [blame] | 27 | } |
Vishnu Nair | cbddf0a | 2020-03-16 16:33:08 -0700 | [diff] [blame] | 28 | return path.resolve(__dirname, 'src/stubs'); |
Vishnu Nair | 92dccb5 | 2020-01-27 15:00:13 -0800 | [diff] [blame] | 29 | } |
| 30 | |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 31 | module.exports = { |
| 32 | entry: './src/main.js', |
| 33 | output: { |
| 34 | path: path.resolve(__dirname, './dist'), |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 35 | filename: 'build.js' |
| 36 | }, |
| 37 | module: { |
| 38 | rules: [ |
| 39 | { |
| 40 | test: /\.vue$/, |
| 41 | loader: 'vue-loader', |
| 42 | options: { |
| 43 | loaders: { |
| 44 | } |
| 45 | // other vue-loader options go here |
| 46 | } |
| 47 | }, |
| 48 | { |
| 49 | test: /\.js$/, |
| 50 | loader: 'babel-loader', |
| 51 | exclude: /node_modules/ |
| 52 | }, |
| 53 | { |
| 54 | test: /\.proto$/, |
| 55 | loader: 'proto-loader', |
| 56 | options: { |
Vishnu Nair | 62d93dd | 2018-02-06 14:40:42 -0800 | [diff] [blame] | 57 | paths: [ |
| 58 | path.resolve(__dirname, '../../..'), |
| 59 | path.resolve(__dirname, '../../../external/protobuf/src') |
| 60 | ] |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 61 | } |
| 62 | }, |
| 63 | { |
| 64 | test: /\.(png|jpg|gif|svg)$/, |
| 65 | loader: 'file-loader', |
| 66 | options: { |
| 67 | name: '[name].[ext]?[hash]' |
| 68 | } |
| 69 | } |
| 70 | ] |
| 71 | }, |
| 72 | resolve: { |
Vishnu Nair | 92dccb5 | 2020-01-27 15:00:13 -0800 | [diff] [blame] | 73 | alias: { |
| 74 | WaylandSafePath: getWaylandSafePath(), |
Vishnu Nair | 92dccb5 | 2020-01-27 15:00:13 -0800 | [diff] [blame] | 75 | }, |
Vishnu Nair | f60b79f | 2017-12-28 11:18:46 -0800 | [diff] [blame] | 76 | modules: [ |
| 77 | 'node_modules', |
| 78 | path.resolve(__dirname, '../../..') |
| 79 | ], |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 80 | }, |
| 81 | resolveLoader: { |
| 82 | modules: [ |
| 83 | 'node_modules', |
| 84 | path.resolve(__dirname, 'loaders') |
| 85 | ] |
| 86 | }, |
| 87 | devServer: { |
| 88 | historyApiFallback: true, |
| 89 | noInfo: true |
| 90 | }, |
| 91 | performance: { |
| 92 | hints: false |
| 93 | }, |
| 94 | devtool: '#eval-source-map' |
| 95 | } |
| 96 | |
Adrian Roos | 77d8a39 | 2017-12-29 16:20:58 +0100 | [diff] [blame] | 97 | var prod = (process.env.NODE_ENV === 'production'); |
| 98 | |
| 99 | if (prod) { |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 100 | module.exports.devtool = '#source-map' |
| 101 | // http://vue-loader.vuejs.org/en/workflow/production.html |
| 102 | module.exports.plugins = (module.exports.plugins || []).concat([ |
| 103 | new webpack.DefinePlugin({ |
| 104 | 'process.env': { |
| 105 | NODE_ENV: '"production"' |
| 106 | } |
| 107 | }), |
| 108 | new webpack.optimize.UglifyJsPlugin({ |
| 109 | sourceMap: true, |
| 110 | compress: { |
| 111 | warnings: false |
| 112 | } |
| 113 | }), |
| 114 | new webpack.LoaderOptionsPlugin({ |
| 115 | minimize: true |
| 116 | }) |
| 117 | ]) |
| 118 | } |
Adrian Roos | 77d8a39 | 2017-12-29 16:20:58 +0100 | [diff] [blame] | 119 | |
| 120 | module.exports.plugins = (module.exports.plugins || []).concat([ |
| 121 | new HtmlWebpackPlugin({ |
| 122 | inlineSource: prod ? '.(js|css)' : false, |
| 123 | template: 'src/index_template.html' |
| 124 | }), |
| 125 | new HtmlWebpackInlineSourcePlugin(), |
| 126 | ]); |