webpack.plugin.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. var path = require('path');
  2. var webpack = require('webpack');
  3. var UglifyJsPlugin = require('webpack/lib/optimize/UglifyJsPlugin');
  4. var ManifestPlugin = require('webpack-manifest-plugin');
  5. var config = {
  6. entry: {
  7. plugin: './resource/js/plugin.js',
  8. },
  9. output: {
  10. path: path.join(__dirname + "/public/js"),
  11. filename: "[name].[hash].js"
  12. },
  13. resolve: {
  14. modules: [
  15. './node_modules', './plugin/node_modules',
  16. ],
  17. },
  18. module: {
  19. rules: [
  20. {
  21. test: /.jsx?$/,
  22. exclude: /node_modules/,
  23. use: [{
  24. loader: 'babel-loader',
  25. }]
  26. },
  27. {
  28. test: /\.css$/,
  29. use: ['style-loader', 'css-loader'],
  30. },
  31. {
  32. test: /\.scss$/,
  33. use: ['style-loader', 'css-loader', 'sass-loader'],
  34. },
  35. ]
  36. },
  37. plugins: []
  38. };
  39. if (process.env && process.env.NODE_ENV !== 'development') {
  40. config.plugins = [
  41. new webpack.DefinePlugin({
  42. 'process.env':{
  43. 'NODE_ENV': JSON.stringify('production')
  44. }
  45. }),
  46. new UglifyJsPlugin({
  47. compress:{
  48. warnings: false
  49. }
  50. }),
  51. ];
  52. }
  53. config.plugins.push(new ManifestPlugin({
  54. fileName: 'manifest-plugin.json'
  55. }));
  56. module.exports = config;