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 22module.exports = { 23 entry: './src/main.js', 24 output: { 25 path: path.resolve(__dirname, './dist'), 26 filename: 'build.js' 27 }, 28 module: { 29 rules: [ 30 { 31 test: /\.vue$/, 32 loader: 'vue-loader', 33 options: { 34 loaders: { 35 } 36 // other vue-loader options go here 37 } 38 }, 39 { 40 test: /\.js$/, 41 loader: 'babel-loader', 42 exclude: /node_modules/ 43 }, 44 { 45 test: /\.proto$/, 46 loader: 'proto-loader', 47 options: { 48 paths: [ 49 path.resolve(__dirname, '../../..'), 50 path.resolve(__dirname, '../../../external/protobuf/src') 51 ] 52 } 53 }, 54 { 55 test: /\.(png|jpg|gif|svg)$/, 56 loader: 'file-loader', 57 options: { 58 name: '[name].[ext]?[hash]' 59 } 60 } 61 ] 62 }, 63 resolve: { 64 modules: [ 65 'node_modules', 66 path.resolve(__dirname, '../../..') 67 ], 68 }, 69 resolveLoader: { 70 modules: [ 71 'node_modules', 72 path.resolve(__dirname, 'loaders') 73 ] 74 }, 75 devServer: { 76 historyApiFallback: true, 77 noInfo: true 78 }, 79 performance: { 80 hints: false 81 }, 82 devtool: '#eval-source-map' 83} 84 85var prod = (process.env.NODE_ENV === 'production'); 86 87if (prod) { 88 module.exports.devtool = '#source-map' 89 // http://vue-loader.vuejs.org/en/workflow/production.html 90 module.exports.plugins = (module.exports.plugins || []).concat([ 91 new webpack.DefinePlugin({ 92 'process.env': { 93 NODE_ENV: '"production"' 94 } 95 }), 96 new webpack.optimize.UglifyJsPlugin({ 97 sourceMap: true, 98 compress: { 99 warnings: false 100 } 101 }), 102 new webpack.LoaderOptionsPlugin({ 103 minimize: true 104 }) 105 ]) 106} 107 108module.exports.plugins = (module.exports.plugins || []).concat([ 109 new HtmlWebpackPlugin({ 110 inlineSource: prod ? '.(js|css)' : false, 111 template: 'src/index_template.html' 112 }), 113 new HtmlWebpackInlineSourcePlugin(), 114]); 115