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 | |
| 17 | var path = require('path') |
| 18 | var webpack = require('webpack') |
Adrian Roos | 77d8a39 | 2017-12-29 16:20:58 +0100 | [diff] [blame] | 19 | var HtmlWebpackPlugin = require('html-webpack-plugin') |
| 20 | var HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin') |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 21 | |
| 22 | module.exports = { |
| 23 | entry: './src/main.js', |
| 24 | output: { |
| 25 | path: path.resolve(__dirname, './dist'), |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 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: { |
Vishnu Nair | 62d93dd | 2018-02-06 14:40:42 -0800 | [diff] [blame] | 48 | paths: [ |
| 49 | path.resolve(__dirname, '../../..'), |
| 50 | path.resolve(__dirname, '../../../external/protobuf/src') |
| 51 | ] |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 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: { |
Vishnu Nair | f60b79f | 2017-12-28 11:18:46 -0800 | [diff] [blame] | 64 | modules: [ |
| 65 | 'node_modules', |
| 66 | path.resolve(__dirname, '../../..') |
| 67 | ], |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 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 | |
Adrian Roos | 77d8a39 | 2017-12-29 16:20:58 +0100 | [diff] [blame] | 85 | var prod = (process.env.NODE_ENV === 'production'); |
| 86 | |
| 87 | if (prod) { |
Vishnu Nair | 46babab | 2017-12-19 15:15:30 -0800 | [diff] [blame] | 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 | } |
Adrian Roos | 77d8a39 | 2017-12-29 16:20:58 +0100 | [diff] [blame] | 107 | |
| 108 | module.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 | ]); |