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 17var path = require('path') 18var webpack = require('webpack') 19var HtmlWebpackPlugin = require('html-webpack-plugin') 20var HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin') 21 22function getWaylandSafePath() { 23 if (process.env.AOSP) { 24 return path.resolve(__dirname, 'src/stubs'); 25 } 26 return path.resolve(__dirname, '../../../vendor/google_arc/libs/wayland_service'); 27} 28 29// b/148409169 remove once proto log support is in AOSP. 30function getProtoLogSafePath() { 31 if (process.env.AOSP) { 32 return path.resolve(__dirname, 'src/stubs'); 33 } 34 return path.resolve(__dirname, '../../../frameworks/base/core/proto/android/server'); 35} 36 37// b/148409169 remove once proto log support is in AOSP. 38function getProtoLogJsonSafePath() { 39 if (process.env.AOSP) { 40 return path.resolve(__dirname, 'src/stubs'); 41 } 42 return path.resolve(__dirname, '../../../frameworks/base/data/etc'); 43} 44 45module.exports = { 46 entry: './src/main.js', 47 output: { 48 path: path.resolve(__dirname, './dist'), 49 filename: 'build.js' 50 }, 51 module: { 52 rules: [ 53 { 54 test: /\.vue$/, 55 loader: 'vue-loader', 56 options: { 57 loaders: { 58 } 59 // other vue-loader options go here 60 } 61 }, 62 { 63 test: /\.js$/, 64 loader: 'babel-loader', 65 exclude: /node_modules/ 66 }, 67 { 68 test: /\.proto$/, 69 loader: 'proto-loader', 70 options: { 71 paths: [ 72 path.resolve(__dirname, '../../..'), 73 path.resolve(__dirname, '../../../external/protobuf/src') 74 ] 75 } 76 }, 77 { 78 test: /\.(png|jpg|gif|svg)$/, 79 loader: 'file-loader', 80 options: { 81 name: '[name].[ext]?[hash]' 82 } 83 } 84 ] 85 }, 86 resolve: { 87 alias: { 88 WaylandSafePath: getWaylandSafePath(), 89 ProtoLogSafePath: getProtoLogSafePath(), 90 ProtoLogJsonSafePath: getProtoLogJsonSafePath(), 91 }, 92 modules: [ 93 'node_modules', 94 path.resolve(__dirname, '../../..') 95 ], 96 }, 97 resolveLoader: { 98 modules: [ 99 'node_modules', 100 path.resolve(__dirname, 'loaders') 101 ] 102 }, 103 devServer: { 104 historyApiFallback: true, 105 noInfo: true 106 }, 107 performance: { 108 hints: false 109 }, 110 devtool: '#eval-source-map' 111} 112 113var prod = (process.env.NODE_ENV === 'production'); 114 115if (prod) { 116 module.exports.devtool = '#source-map' 117 // http://vue-loader.vuejs.org/en/workflow/production.html 118 module.exports.plugins = (module.exports.plugins || []).concat([ 119 new webpack.DefinePlugin({ 120 'process.env': { 121 NODE_ENV: '"production"' 122 } 123 }), 124 new webpack.optimize.UglifyJsPlugin({ 125 sourceMap: true, 126 compress: { 127 warnings: false 128 } 129 }), 130 new webpack.LoaderOptionsPlugin({ 131 minimize: true 132 }) 133 ]) 134} 135 136module.exports.plugins = (module.exports.plugins || []).concat([ 137 new HtmlWebpackPlugin({ 138 inlineSource: prod ? '.(js|css)' : false, 139 template: 'src/index_template.html' 140 }), 141 new HtmlWebpackInlineSourcePlugin(), 142]); 143