webpack.config.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. const path = require('path')
  2. const webpack = require('webpack')
  3. const MiniCssExtractPlugin = require('mini-css-extract-plugin');
  4. const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
  5. const bundleOutputDir = './wwwroot/dist'
  6. const VueLoaderPlugin = require('vue-loader/lib/plugin')
  7. module.exports = () => {
  8. // console.log('Building for \x1b[33m%s\x1b[0m', process.env.NODE_ENV)
  9. const isDevBuild = !(process.env.NODE_ENV && process.env.NODE_ENV === 'production')
  10. const extractCSS = new MiniCssExtractPlugin({
  11. filename: 'style.css'
  12. })
  13. return [{
  14. mode: (isDevBuild ? 'development' : 'production'),
  15. stats: { modules: false },
  16. entry: { 'main': './ClientApp/boot-app.js' },
  17. resolve: {
  18. extensions: ['.js', '.vue'],
  19. alias: isDevBuild ? {
  20. 'vue$': 'vue/dist/vue',
  21. 'components': path.resolve(__dirname, './ClientApp/components'),
  22. 'views': path.resolve(__dirname, './ClientApp/views'),
  23. 'utils': path.resolve(__dirname, './ClientApp/utils'),
  24. 'api': path.resolve(__dirname, './ClientApp/store/api'),
  25. '@': path.resolve(__dirname, './ClientApp'),
  26. } : {
  27. 'components': path.resolve(__dirname, './ClientApp/components'),
  28. 'views': path.resolve(__dirname, './ClientApp/views'),
  29. 'utils': path.resolve(__dirname, './ClientApp/utils'),
  30. 'api': path.resolve(__dirname, './ClientApp/store/api'),
  31. '@': path.resolve(__dirname, './ClientApp'),
  32. }
  33. },
  34. output: {
  35. path: path.join(__dirname, bundleOutputDir),
  36. filename: '[name].js',
  37. publicPath: '/dist/'
  38. },
  39. module: {
  40. rules: [
  41. {
  42. test: /\.vue$/, use: 'vue-loader', include: [
  43. //path.resolve(__dirname, '/ClientApp/'),
  44. //path.resolve(__dirname, '/node_modules/'),
  45. path.resolve(__dirname, '/')
  46. ]
  47. },
  48. {
  49. test: /\.js$/, use: 'babel-loader', include: [
  50. //path.resolve(__dirname, '/ClientApp/'),
  51. //path.resolve(__dirname, '/node_modules/'),
  52. path.resolve(__dirname, '/')
  53. ]
  54. },
  55. { test: /\.css$/, use: isDevBuild ? ['style-loader', 'css-loader'] : [MiniCssExtractPlugin.loader, 'css-loader'] },
  56. { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' },
  57. { test: /\.(eot|ttf|woff|woff2)$/, loader: 'file-loader' },
  58. { test: /\.less$/, use: [{ loader: "style-loader" }, { loader: "css-loader" }, { loader: "less-loader", options: { javascriptEnabled: true } }] }
  59. ]
  60. },
  61. plugins: [
  62. new VueLoaderPlugin(),
  63. new webpack.DllReferencePlugin({
  64. context: __dirname,
  65. manifest: require('./wwwroot/dist/vendor-manifest.json')
  66. })
  67. ].concat(isDevBuild ? [
  68. new webpack.SourceMapDevToolPlugin({
  69. filename: '[file].map', // Remove this line if you prefer inline source maps
  70. moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
  71. })
  72. ] : [
  73. extractCSS,
  74. new OptimizeCSSPlugin({
  75. cssProcessorOptions: {
  76. safe: true
  77. }
  78. })
  79. ])
  80. }]
  81. }