Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.79 KB | None | 0 0
  1. const Path = require('path');
  2. const HtmlWebpackPlugin = require('html-webpack-plugin');
  3. const Webpack = require('webpack');
  4. const ExtractTextPlugin = require('extract-text-webpack-plugin');
  5. const CopyWebpackPlugin = require('copy-webpack-plugin');
  6.  
  7. module.exports = (options) => {
  8. const ExtractSASS = new ExtractTextPlugin(`/styles/${options.cssFileName}`);
  9.  
  10. const webpackConfig = {
  11. devtool: options.devtool,
  12. entry: [
  13. `webpack-dev-server/client?http://localhost:${+options.port}`,
  14. 'webpack/hot/dev-server',
  15. Path.join(__dirname, '../src/app/index'),
  16. ],
  17. output: {
  18. path: Path.join(__dirname, '../dist'),
  19. filename: `/scripts/${options.jsFileName}`,
  20. },
  21. resolve: {
  22. extensions: ['', '.js', '.jsx', '.css'],
  23. },
  24. module: {
  25. loaders: [
  26. {
  27. test: /.jsx?$/,
  28. include: Path.join(__dirname, '../src/app'),
  29. loader: 'babel',
  30. },
  31. {
  32. test: /\.css$/,
  33. include: [Path.resolve(__dirname, 'not_exist_path')],
  34. loader: ['style-loader', 'css-loader'],
  35. },
  36. ],
  37. },
  38. plugins: [
  39. new Webpack.DefinePlugin({
  40. 'process.env': {
  41. NODE_ENV: JSON.stringify(options.isProduction ? 'production' : 'development'),
  42. },
  43. }),
  44. new HtmlWebpackPlugin(
  45. {
  46. template: Path.join(__dirname, '../src/index.html'),
  47. },
  48. new CopyWebpackPlugin([
  49. {
  50. from: '../static/',
  51. to: 'static',
  52. },
  53. ])
  54. ),
  55. ],
  56. };
  57.  
  58. if (options.isProduction) {
  59. webpackConfig.entry = [Path.join(__dirname, '../src/app/index')];
  60.  
  61. webpackConfig.plugins.push(
  62. new Webpack.optimize.OccurenceOrderPlugin(),
  63. new Webpack.optimize.UglifyJsPlugin({
  64. compressor: {
  65. warnings: false,
  66. },
  67. }),
  68. ExtractSASS
  69. );
  70.  
  71. webpackConfig.module.loaders.push({
  72. test: /\.scss$/,
  73. loader: ExtractSASS.extract(['css', 'sass']),
  74. });
  75. } else {
  76. webpackConfig.plugins.push(new Webpack.HotModuleReplacementPlugin());
  77.  
  78. webpackConfig.module.loaders.push({
  79. test: /\.scss$/,
  80. loaders: ['style', 'css', 'sass'],
  81. });
  82.  
  83. webpackConfig.module.loaders.push({
  84. test: /\.css$/,
  85. include: /node_modules/,
  86. loaders: ['style-loader', 'css-loader'],
  87. });
  88.  
  89. webpackConfig.devServer = {
  90. contentBase: Path.join(__dirname, '../'),
  91. hot: true,
  92. port: options.port,
  93. inline: true,
  94. progress: true,
  95. historyApiFallback: true,
  96. stats: 'errors-only',
  97. disableHostCheck: true,
  98. proxy: {
  99. '/api': 'http://localhost:4000',
  100. },
  101. allowedHosts: ['.amazonaws.com'],
  102. };
  103. }
  104.  
  105. return webpackConfig;
  106. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement