抖音小程序发布平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 

156 行
5.9 KiB

  1. var path = require('path');
  2. var webpack = require('webpack');
  3. const CopyWebpackPlugin = require('copy-webpack-plugin');
  4. const HtmlWebpackPlugin = require('html-webpack-plugin');
  5. const CleanWebpackPlugin = require('clean-webpack-plugin');
  6. const packageInfo = require('./package.json');
  7. const CompressionWebpackPlugin = require("compression-webpack-plugin");
  8. module.exports = (env = {}) =>{
  9. console.log(`------------------- ${env.Generative?'生产':'开发'}环境 -------------------`);
  10. var plugins = (module.exports.plugins || []).concat([
  11. new CleanWebpackPlugin(['dist']),
  12. new webpack.optimize.UglifyJsPlugin({
  13. // sourceMap: true,
  14. // compress: {
  15. // warnings: false
  16. // }
  17. }),
  18. new webpack.LoaderOptionsPlugin({
  19. minimize: true
  20. })
  21. ])
  22. if(!env.Generative){
  23. plugins = [];
  24. }
  25. plugins.push(
  26. new CompressionWebpackPlugin({
  27. filename: '[path].gz[query]', //压缩后的文件名
  28. algorithm: 'gzip',// 压缩格式 有:gzip、brotliCompress、
  29. test: /\.(js|css|svg)$/,
  30. threshold: 10240,// 只处理比这个值大的资源,按字节算
  31. minRatio: 0.8, //只有压缩率比这个值小的文件才会被处理,压缩率=压缩大小/原始大小,如果压缩后和原始文件大小没有太大区别,就不用压缩
  32. deleteOriginalAssets: false //是否删除原文件,最好不删除,服务器会自动优先返回同名的.gzip资源,如果找不到还可以拿原始文件
  33. }));
  34. plugins.push(new CopyWebpackPlugin([{
  35. // from: './src/static',
  36. // to: 'static'
  37. from : path.join(__dirname,'./src/static'),
  38. to : 'static'
  39. }]));
  40. plugins.push(new HtmlWebpackPlugin({
  41. // title: "自动生成网页标题",
  42. filename: "./index.html",
  43. hash:true,
  44. showErrors: true,
  45. version: packageInfo.version,
  46. template: './src/index.html'
  47. }));
  48. return {
  49. entry: {
  50. app:['babel-polyfill','./src/main.js'],
  51. vendor: ['vue', 'vue-router', 'vuex', 'element-ui']
  52. },
  53. output: {
  54. path: path.resolve(__dirname, './dist'),//输出结果
  55. publicPath: env.production ? './' : '/', //文件路径
  56. filename: '[name].js',
  57. chunkFilename: 'js/[name].js'
  58. },
  59. module: {
  60. rules: [
  61. // 使用vue-loader 加载 .vue 结尾的文件
  62. {
  63. test: /\.vue$/,
  64. loader: 'vue-loader',
  65. options: {
  66. loaders: {
  67. },
  68. // other vue-loader options go here
  69. presets: ['es2015'],
  70. plugins: ['transform-runtime', 'transform-object-rest-spread']
  71. },
  72. // query: {
  73. // }
  74. },
  75. // 使用babel 加载 .js 结尾的文件
  76. {
  77. test: /\.js$/,
  78. loader: 'babel-loader',
  79. exclude: /node_modules/
  80. },
  81. // 加载图标
  82. {
  83. test: /\.(png|jpg|gif|svg)$/,
  84. loader: 'file-loader',
  85. options: {
  86. name: '[name].[ext]?[hash]',
  87. limit: 8192,
  88. outputPath: 'static/images/'
  89. }
  90. },
  91. //加载css
  92. {
  93. test: /\.css$/,
  94. loader: "style-loader!css-loader",
  95. // loader: 'style-loader!css-loader?modules&importLoaders=1&localIdentName=[name]__[local]___[hash:base64:5]',
  96. // exclude: /node_modules/
  97. },
  98. // {
  99. // test: /\.scss$/,
  100. // loader: "style-loader!css-loader!sass-loader!"
  101. // },
  102. // {
  103. // test: /\.(woff|woff2|svg|ttf|eot)$/,
  104. // use:[
  105. // {loader:'file-loader',options:{name:'fonts/[name].[hash:8].[ext]'}}//项目设置打包到dist下的fonts文件夹下
  106. // // {loader:'url-loader',options:{name:'fonts/[name].[hash:8].[ext]'}}//项目设置打包到dist下的fonts文件夹下
  107. // ]
  108. // },
  109. {
  110. test: /\.(woff|woff2|svg|eot|ttf)\??.*$/,
  111. // loader: 'url-loader'
  112. loader:'url-loader',options:{name:'fonts/[name].[hash:8].[ext]'}//项目设置打包到dist下的fonts文件夹下
  113. },
  114. // {
  115. // test: /\.html$/,
  116. // loader: 'html-loader',
  117. // options: {
  118. // minimize: false
  119. // }
  120. // }
  121. ]
  122. },
  123. resolve: {
  124. alias: {
  125. 'vue$': 'vue/dist/vue.esm.js'
  126. }
  127. },
  128. externals: {
  129. "BMap": "BMap"
  130. },
  131. devServer: {
  132. inline: true, //检测文件变化,实时构建并刷新浏览器
  133. port: "8880",
  134. proxy: {
  135. '/T': {
  136. target: 'https://opendouyinapitest.malls.iformall.com/T',
  137. // target: 'http://10.100.30.171:6060',
  138. pathRewrite: {
  139. "^/T": ""
  140. },
  141. secure: false,
  142. changeOrigin: true
  143. },
  144. },
  145. historyApiFallback: true,
  146. },
  147. performance: {
  148. hints: false
  149. },
  150. plugins:plugins,
  151. // devtool: '#eval-source-map'//开发模式下更方便定位错误
  152. devtool:env.Generative?false:'#eval-source-map'
  153. }
  154. }