|
1 | | -var isDevBuild = process.argv.indexOf('--env.prod') < 0; |
2 | | -var path = require('path'); |
3 | | -var webpack = require('webpack'); |
4 | | -var ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 1 | +const path = require('path'); |
| 2 | +const webpack = require('webpack'); |
| 3 | +const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 4 | +const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; |
| 5 | +const bundleOutputDir = './wwwroot/dist'; |
5 | 6 |
|
6 | | -var bundleOutputDir = './wwwroot/dist'; |
7 | | -module.exports = { |
8 | | - devtool: isDevBuild ? 'inline-source-map' : null, |
9 | | - entry: { 'main': './ClientApp/boot.tsx' }, |
10 | | - resolve: { extensions: [ '', '.js', '.jsx', '.ts', '.tsx' ] }, |
11 | | - output: { |
12 | | - path: path.join(__dirname, bundleOutputDir), |
13 | | - filename: '[name].js', |
14 | | - publicPath: '/dist/' |
15 | | - }, |
16 | | - module: { |
17 | | - loaders: [ |
18 | | - { test: /\.ts(x?)$/, include: /ClientApp/, loader: 'babel-loader' }, |
19 | | - { test: /\.tsx?$/, include: /ClientApp/, loader: 'ts-loader', query: { silent: true } }, |
20 | | - { test: /\.css$/, loader: isDevBuild ? 'style-loader!css-loader' : ExtractTextPlugin.extract(['css-loader']) }, |
21 | | - { test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } }, |
22 | | - { test: /\.json$/, loader: 'json-loader' } |
23 | | - ] |
24 | | - }, |
25 | | - plugins: [ |
26 | | - new webpack.DllReferencePlugin({ |
27 | | - context: __dirname, |
28 | | - manifest: require('./wwwroot/dist/vendor-manifest.json') |
29 | | - }) |
30 | | - ].concat(isDevBuild ? [ |
31 | | - // Plugins that apply in development builds only |
32 | | - new webpack.SourceMapDevToolPlugin({ |
33 | | - filename: '[file].map', // Remove this line if you prefer inline source maps |
34 | | - moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk |
35 | | - }) |
36 | | - ] : [ |
37 | | - // Plugins that apply in production builds only |
38 | | - new webpack.optimize.OccurenceOrderPlugin(), |
39 | | - new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), |
40 | | - new ExtractTextPlugin('site.css') |
41 | | - ]) |
| 7 | +module.exports = (env) => { |
| 8 | + const isDevBuild = !(env && env.prod); |
| 9 | + return [{ |
| 10 | + stats: { modules: false }, |
| 11 | + entry: { 'main': './ClientApp/boot.tsx' }, |
| 12 | + resolve: { extensions: [ '.js', '.jsx', '.ts', '.tsx' ] }, |
| 13 | + output: { |
| 14 | + path: path.join(__dirname, bundleOutputDir), |
| 15 | + filename: '[name].js', |
| 16 | + publicPath: '/dist/' |
| 17 | + }, |
| 18 | + module: { |
| 19 | + rules: [ |
| 20 | + { test: /\.ts(x?)$/, include: /ClientApp/, use: 'babel-loader' }, |
| 21 | + { test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' }, |
| 22 | + { test: /\.css$/, loader: isDevBuild ? 'style-loader!css-loader' : ExtractTextPlugin.extract({ loader: 'css-loader' }) }, |
| 23 | + { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' } |
| 24 | + ] |
| 25 | + }, |
| 26 | + plugins: [ |
| 27 | + new CheckerPlugin(), |
| 28 | + new webpack.DllReferencePlugin({ |
| 29 | + context: __dirname, |
| 30 | + manifest: require('./wwwroot/dist/vendor-manifest.json') |
| 31 | + }) |
| 32 | + ].concat(isDevBuild ? [ |
| 33 | + // Plugins that apply in development builds only |
| 34 | + new webpack.SourceMapDevToolPlugin({ |
| 35 | + filename: '[file].map', // Remove this line if you prefer inline source maps |
| 36 | + moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk |
| 37 | + }) |
| 38 | + ] : [ |
| 39 | + // Plugins that apply in production builds only |
| 40 | + new webpack.optimize.UglifyJsPlugin(), |
| 41 | + new ExtractTextPlugin('site.css') |
| 42 | + ]) |
| 43 | + }]; |
42 | 44 | }; |
0 commit comments