webpack.conf.js 3.2 KB

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