webpack.config.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. var path = require('path');
  2. var webpack = require('webpack');
  3. var HtmlWebpackPlugin = require('html-webpack-plugin');
  4. var BrowserSyncPlugin = require('browser-sync-webpack-plugin');
  5. // var CopyWebpackPlugin = require('copy-webpack-plugin');
  6. var { CleanWebpackPlugin } = require('clean-webpack-plugin');
  7. var definePlugin = new webpack.DefinePlugin({
  8. 'process.env.DEV': JSON.stringify(JSON.parse(process.env.DEV || 'false')),
  9. 'process.env.SERVER_URL': JSON.stringify(process.env.SERVER_URL || 'http://109.214.245.153'),
  10. 'process.env.SERVER_PORT': JSON.stringify(process.env.SERVER_PORT || '2610')
  11. });
  12. var outpath = './webpack/';
  13. if (!process.env.DEV || process.env.DEV === false) {
  14. console.log('CORDOVA environment');
  15. outpath = 'www/';
  16. } else {
  17. console.log('DEV environment');
  18. }
  19. // new CopyWebpackPlugin([
  20. // {
  21. // context: path.resolve(__dirname, 'src', 'assets'),
  22. // from: '**/*',
  23. // to: path.resolve(__dirname, outpath, 'assets')
  24. // }
  25. // ]),
  26. module.exports = {
  27. devtool: 'cheap-source-map',
  28. mode: 'development',
  29. entry: {
  30. app: path.resolve(__dirname, 'src/main.js')
  31. },
  32. output: {
  33. filename: 'app.bundle.js',
  34. path: path.resolve(__dirname, outpath)
  35. },
  36. plugins: [
  37. definePlugin,
  38. new CleanWebpackPlugin(),
  39. new HtmlWebpackPlugin({
  40. template: './src/index.html'
  41. }),
  42. new BrowserSyncPlugin({
  43. host: process.env.IP || 'localhost',
  44. port: process.env.PORT || 3000,
  45. server: {
  46. baseDir: [outpath, './build']
  47. },
  48. browser: ["firefox"]
  49. }),
  50. new BrowserSyncPlugin({
  51. host: process.env.IP || 'localhost',
  52. port: process.env.PORT || 3005,
  53. server: {
  54. baseDir: [outpath, './build']
  55. },
  56. browser: ["firefox"]
  57. }),
  58. new webpack.DefinePlugin({
  59. CANVAS_RENDERER: JSON.stringify(true),
  60. WEBGL_RENDERER: JSON.stringify(true)
  61. })
  62. ],
  63. module: {
  64. rules: [
  65. { test: /\.js$/, exclude: /(node_modules|server)/, loaders: "babel-loader" },
  66. {
  67. test: /\.(png|svg|jpg|gif)$/,
  68. use: {
  69. loader: 'file-loader',
  70. options: {
  71. esModule: false
  72. }
  73. }
  74. },
  75. {
  76. test: /\.html$/,
  77. exclude: /index.html/,
  78. use: [
  79. {
  80. loader: 'html-loader',
  81. options: { minimize: true }
  82. }
  83. ]
  84. },
  85. {
  86. test: [/\.vert$/, /\.frag$/],
  87. use: "raw-loader"
  88. }
  89. ]
  90. }
  91. };