webpack.config.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 definePlugin = new webpack.DefinePlugin({
  6. __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true'))
  7. });
  8. module.exports = {
  9. devtool: 'cheap-source-map',
  10. mode: 'development',
  11. entry: {
  12. polyfills: './src/polyfills.js',
  13. app: path.resolve(__dirname, 'src/main.js'),
  14. },
  15. target: 'web',
  16. watch: true,
  17. output: {
  18. pathinfo: true,
  19. filename: '[name].bundle.js',
  20. chunkFilename: '[name].bundle.js',
  21. path: path.resolve(__dirname, 'dist')
  22. },
  23. optimization: {
  24. splitChunks: {
  25. cacheGroups: {
  26. commons: { test: /[\\/]node_modules[\\/]/, name: "vendors", chunks: "all" }
  27. }
  28. }
  29. },
  30. plugins: [
  31. definePlugin,
  32. new HtmlWebpackPlugin({
  33. filename: '../index.html',
  34. template: './src/index.html',
  35. chunksSortMode: "manual",
  36. chunks: ['polyfills', 'vendors', 'app'],
  37. minify: {
  38. removeAttributeQuotes: false,
  39. collapseWhitespace: false,
  40. html5: false,
  41. minifyCSS: false,
  42. minifyJS: false,
  43. minifyURLs: false,
  44. removeComments: false,
  45. removeEmptyAttributes: false
  46. },
  47. hash: false
  48. }),
  49. new BrowserSyncPlugin({
  50. host: process.env.IP || 'localhost',
  51. port: process.env.PORT || 3000,
  52. server: {
  53. baseDir: ['./', './build']
  54. }
  55. }),
  56. new webpack.DefinePlugin({
  57. CANVAS_RENDERER: JSON.stringify(true),
  58. WEBGL_RENDERER: JSON.stringify(true)
  59. })
  60. ],
  61. module: {
  62. rules: [
  63. { test: /\.js$/, exclude: /node_modules/, loaders: "babel-loader" },
  64. {
  65. test: /\.(gif|png|jpe?g|svg|xml)$/i,
  66. use: "file-loader"
  67. },
  68. {
  69. test: [/\.vert$/, /\.frag$/],
  70. use: "raw-loader"
  71. }
  72. ]
  73. }
  74. };