webpack.conf.js 3.6 KB

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