webpack.web.config.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. "use strict";
  2. process.env.BABEL_ENV = "web";
  3. const path = require("path");
  4. const webpack = require("webpack");
  5. const BabiliWebpackPlugin = require("babili-webpack-plugin");
  6. const CopyWebpackPlugin = require("copy-webpack-plugin");
  7. const ExtractTextPlugin = require("extract-text-webpack-plugin");
  8. const HtmlWebpackPlugin = require("html-webpack-plugin");
  9. let webConfig = {
  10. devtool: "#cheap-module-eval-source-map",
  11. entry: {
  12. web: path.join(__dirname, "../src/renderer/main.js")
  13. },
  14. module: {
  15. rules: [
  16. {
  17. test: /\.vue$/,
  18. use: [
  19. {
  20. loader: "vue-loader",
  21. options: {
  22. loaders: {
  23. less: ExtractTextPlugin.extract({
  24. use: [
  25. "css-loader?minimize",
  26. "autoprefixer-loader",
  27. "less-loader"
  28. ],
  29. fallback: "vue-style-loader"
  30. }),
  31. css: ExtractTextPlugin.extract({
  32. use: ["css-loader", "autoprefixer-loader", "less-loader"],
  33. fallback: "vue-style-loader"
  34. }),
  35. scss: ExtractTextPlugin.extract({
  36. use: ["css-loader", "autoprefixer-loader", "sass-loader"],
  37. fallback: "vue-style-loader"
  38. })
  39. }
  40. }
  41. },
  42. {
  43. loader: "iview-loader",
  44. options: {
  45. prefix: false
  46. }
  47. }
  48. ]
  49. },
  50. {
  51. test: /iview\/.*?js$/,
  52. loader: "babel-loader"
  53. },
  54. {
  55. test: /\.js$/,
  56. loader: "babel-loader",
  57. exclude: /node_modules/
  58. },
  59. {
  60. test: /\.css$/,
  61. use: ExtractTextPlugin.extract({
  62. use: ["css-loader?minimize", "autoprefixer-loader"],
  63. fallback: "style-loader"
  64. })
  65. },
  66. {
  67. test: /\.less/,
  68. use: ExtractTextPlugin.extract({
  69. use: ["css-loader?minimize", "autoprefixer-loader", "less-loader"],
  70. fallback: "style-loader"
  71. })
  72. },
  73. {
  74. test: /\.scss/,
  75. use: ExtractTextPlugin.extract({
  76. use: ["css-loader?minimize", "autoprefixer-loader", "sass-loader"],
  77. fallback: "style-loader"
  78. })
  79. },
  80. {
  81. test: /\.(gif|jpg|png|woff|svg|eot|ttf)\??.*$/,
  82. loader: "url-loader?limit=1024"
  83. },
  84. {
  85. test: /\.(html|tpl)$/,
  86. loader: "html-loader"
  87. }
  88. ]
  89. },
  90. plugins: [
  91. new ExtractTextPlugin("styles.css"),
  92. new HtmlWebpackPlugin({
  93. filename: "index.html",
  94. template: path.resolve(__dirname, "../src/index.ejs"),
  95. minify: {
  96. collapseWhitespace: true,
  97. removeAttributeQuotes: true,
  98. removeComments: true
  99. },
  100. nodeModules: false
  101. }),
  102. new webpack.DefinePlugin({
  103. "process.env.IS_WEB": "true"
  104. }),
  105. new webpack.HotModuleReplacementPlugin(),
  106. new webpack.NoEmitOnErrorsPlugin()
  107. ],
  108. output: {
  109. filename: "[name].js",
  110. path: path.join(__dirname, "../dist/web")
  111. },
  112. resolve: {
  113. alias: {
  114. "@": path.join(__dirname, "../src/renderer"),
  115. vue$: "vue/dist/vue.esm.js"
  116. },
  117. extensions: [".js", ".vue", ".json", ".css"]
  118. },
  119. target: "web"
  120. };
  121. /**
  122. * Adjust webConfig for production settings
  123. */
  124. if (process.env.NODE_ENV === "production") {
  125. webConfig.devtool = "";
  126. webConfig.plugins.push(
  127. new BabiliWebpackPlugin(),
  128. new CopyWebpackPlugin([
  129. {
  130. from: path.join(__dirname, "../static"),
  131. to: path.join(__dirname, "../dist/web/static"),
  132. ignore: [".*"]
  133. }
  134. ]),
  135. new webpack.DefinePlugin({
  136. "process.env.NODE_ENV": '"production"'
  137. }),
  138. new webpack.LoaderOptionsPlugin({
  139. minimize: true
  140. })
  141. );
  142. }
  143. module.exports = webConfig;