webpack.config.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. });
  10. var outpath = './webpack/';
  11. if (!process.env.DEV || process.env.DEV === false) {
  12. console.log('CORDOVA environment');
  13. outpath = 'www/';
  14. } else {
  15. console.log('DEV environment');
  16. }
  17. module.exports = {
  18. devtool: 'eval-source-map',
  19. mode: 'development',
  20. entry: {
  21. app: path.resolve(__dirname, 'src/main.js')
  22. },
  23. target: 'web',
  24. watch: true,
  25. output: {
  26. filename: 'app.bundle.js',
  27. path: path.resolve(__dirname, outpath + 'dist')
  28. },
  29. plugins: [
  30. definePlugin,
  31. new CleanWebpackPlugin(),
  32. new CopyWebpackPlugin([
  33. {
  34. context: path.resolve(__dirname, 'src', 'assets'),
  35. from: '**/*',
  36. to: path.resolve(__dirname, outpath, 'assets')
  37. }
  38. ]),
  39. new HtmlWebpackPlugin({
  40. filename: '../index.html',
  41. template: './src/index.html',
  42. minify: {
  43. removeAttributeQuotes: false,
  44. collapseWhitespace: false,
  45. html5: false,
  46. minifyCSS: false,
  47. minifyJS: false,
  48. minifyURLs: false,
  49. removeComments: false,
  50. removeEmptyAttributes: false
  51. },
  52. hash: false,
  53. inject: true
  54. }),
  55. new BrowserSyncPlugin({
  56. host: process.env.IP || 'localhost',
  57. port: process.env.PORT || 3000,
  58. server: {
  59. baseDir: [outpath, './build']
  60. },
  61. browser: ["firefox"]
  62. }),
  63. new BrowserSyncPlugin({
  64. host: process.env.IP || 'localhost',
  65. port: process.env.PORT || 3005,
  66. server: {
  67. baseDir: [outpath, './build']
  68. },
  69. browser: ["firefox"]
  70. }),
  71. new webpack.DefinePlugin({
  72. CANVAS_RENDERER: JSON.stringify(true),
  73. WEBGL_RENDERER: JSON.stringify(true)
  74. })
  75. ],
  76. module: {
  77. rules: [
  78. { test: /\.js$/, exclude: /(node_modules|server)/, loaders: "babel-loader" },
  79. {
  80. test: /\.(gif|png|jpe?g|svg|xml)$/i,
  81. use: "file-loader"
  82. },
  83. {
  84. test: [/\.vert$/, /\.frag$/],
  85. use: "raw-loader"
  86. }
  87. ]
  88. }
  89. };