webpack.conf.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. const path = require('path');
  2. const webpack = require('webpack');
  3. const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin');
  4. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  5. const utils = require('./utils');
  6. const vueLoaderConfig = require('./vue-loader.conf');
  7. const IS_DEV = process.env.NODE_ENV === 'development';
  8. const DIST = 'dist';
  9. function resolve (dir) {
  10. return path.join(__dirname, '..', dir)
  11. }
  12. module.exports = {
  13. entry: {
  14. 'background/app.js': './src/background/app.js',
  15. 'options/app.js': './src/options/app.js',
  16. 'popup/app.js': './src/popup/app.js',
  17. },
  18. output: {
  19. path: DIST,
  20. publicPath: '/',
  21. filename: '[name].js',
  22. },
  23. resolve: {
  24. extensions: ['.js', '.vue', '.json'],
  25. alias: {
  26. src: resolve('src'),
  27. }
  28. },
  29. module: {
  30. rules: [
  31. {
  32. test: /\.(js|vue)$/,
  33. loader: 'eslint-loader',
  34. enforce: 'pre',
  35. include: [resolve('src'), resolve('test')],
  36. options: {
  37. formatter: require('eslint-friendly-formatter')
  38. }
  39. },
  40. {
  41. test: /\.vue$/,
  42. loader: 'vue-loader',
  43. options: vueLoaderConfig
  44. },
  45. {
  46. test: /\.js$/,
  47. loader: 'babel-loader',
  48. include: [resolve('src'), resolve('test')]
  49. },
  50. ].concat(utils.styleLoaders({
  51. sourceMap: false,
  52. extract: !IS_DEV,
  53. })),
  54. },
  55. // cheap-module-eval-source-map is faster for development
  56. devtool: IS_DEV ? '#cheap-module-eval-source-map' : false,
  57. plugins: [
  58. new webpack.DefinePlugin({
  59. 'process.env': {},
  60. }),
  61. // split vendor js into its own file
  62. new webpack.optimize.CommonsChunkPlugin({
  63. name: 'vendor',
  64. }),
  65. new FriendlyErrorsPlugin(),
  66. ... IS_DEV ? [
  67. // https://github.com/ampedandwired/html-webpack-plugin
  68. // new HtmlWebpackPlugin({
  69. // filename: 'index.html',
  70. // template: 'src/public/index.ejs',
  71. // inject: true,
  72. // config,
  73. // })
  74. ] : [
  75. // extract css into its own file
  76. new ExtractTextPlugin(`${DIST}/[name].css`),
  77. // generate dist index.html with correct asset hash for caching.
  78. // you can customize output by editing /index.html
  79. // see https://github.com/ampedandwired/html-webpack-plugin
  80. // new HtmlWebpackPlugin({
  81. // filename: 'index.html',
  82. // template: 'src/public/index.ejs',
  83. // inject: true,
  84. // minify: {
  85. // removeComments: true,
  86. // collapseWhitespace: true,
  87. // removeAttributeQuotes: true
  88. // // more options:
  89. // // https://github.com/kangax/html-minifier#options-quick-reference
  90. // },
  91. // // necessary to consistently work with multiple chunks via CommonsChunkPlugin
  92. // chunksSortMode: 'dependency'
  93. // }),
  94. new webpack.optimize.UglifyJsPlugin({
  95. compress: {
  96. warnings: false
  97. }
  98. }),
  99. ],
  100. ],
  101. };