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 17const fs = require('fs'); 18var path = require('path') 19var webpack = require('webpack') 20var HtmlWebpackPlugin = require('html-webpack-plugin') 21var HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin') 22 23function getWaylandSafePath() { 24 waylandPath = path.resolve(__dirname, '../../../vendor/google_arc/libs/wayland_service'); 25 if (fs.existsSync(waylandPath)) { 26 return waylandPath; 27 } 28 return path.resolve(__dirname, 'src/stubs'); 29} 30 31module.exports = { 32 entry: './src/main.js', 33 output: { 34 path: path.resolve(__dirname, './dist'), 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: { 57 paths: [ 58 path.resolve(__dirname, '../../..'), 59 path.resolve(__dirname, '../../../external/protobuf/src') 60 ] 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: { 73 alias: { 74 WaylandSafePath: getWaylandSafePath(), 75 }, 76 modules: [ 77 'node_modules', 78 path.resolve(__dirname, '../../..') 79 ], 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 97var prod = (process.env.NODE_ENV === 'production'); 98 99if (prod) { 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} 119 120module.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]); 127