Make Aurelia webpack config as consistent as possible with the other templates

This commit is contained in:
Steve Sanderson
2017-05-04 12:36:25 +01:00
parent 37df30929c
commit e3a8c13c22
2 changed files with 27 additions and 33 deletions

View File

@@ -1,30 +1,28 @@
const path = require('path'); const path = require('path');
const webpack = require('webpack'); const webpack = require('webpack');
const { AureliaPlugin } = require('aurelia-webpack-plugin'); const { AureliaPlugin } = require('aurelia-webpack-plugin');
module.exports = ({ prod } = {}) => {
const isDevBuild = !prod;
const isProdBuild = prod;
const bundleOutputDir = './wwwroot/dist'; const bundleOutputDir = './wwwroot/dist';
return { module.exports = (env) => {
resolve: { const isDevBuild = !(env && env.prod);
extensions: [".ts", ".js"], return [{
modules: ["ClientApp", "node_modules"], stats: { modules: false },
},
entry: { 'app': 'aurelia-bootstrapper' }, entry: { 'app': 'aurelia-bootstrapper' },
resolve: {
extensions: ['.ts', '.js'],
modules: ['ClientApp', 'node_modules'],
},
output: { output: {
path: path.resolve(bundleOutputDir), path: path.resolve(bundleOutputDir),
publicPath: "/dist/", publicPath: '/dist/',
filename: '[name].js' filename: '[name].js'
}, },
module: { module: {
rules: [ rules: [
{ test: /\.css$/i, use: [isDevBuild ? 'css-loader' : 'css-loader?minimize'] }, { test: /\.ts$/i, include: /ClientApp/, use: 'ts-loader?silent=true' },
{ test: /\.html$/i, use: ["html-loader"] }, { test: /\.html$/i, use: 'html-loader' },
{ test: /\.ts$/i, loaders: ['ts-loader'], exclude: path.resolve(__dirname, 'node_modules') }, { test: /\.css$/i, use: isDevBuild ? 'css-loader' : 'css-loader?minimize' },
{ test: /\.json$/i, loader: 'json-loader', exclude: path.resolve(__dirname, 'node_modules') }, { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, loader: 'url-loader', query: { limit: 8192 } }
] ]
}, },
plugins: [ plugins: [
@@ -33,19 +31,14 @@ module.exports = ({ prod } = {}) => {
context: __dirname, context: __dirname,
manifest: require('./wwwroot/dist/vendor-manifest.json') manifest: require('./wwwroot/dist/vendor-manifest.json')
}), }),
new AureliaPlugin({ aureliaApp: "boot" }), new AureliaPlugin({ aureliaApp: 'boot' })
...when(isDevBuild, [ ].concat(isDevBuild ? [
new webpack.SourceMapDevToolPlugin({ new webpack.SourceMapDevToolPlugin({
filename: '[file].map', filename: '[file].map', // Remove this line if you prefer inline source maps
moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
}) })
]), ] : [
...when(isProdBuild, [
new webpack.optimize.UglifyJsPlugin() new webpack.optimize.UglifyJsPlugin()
]) ])
] }];
};
} }
const ensureArray = (config) => config && (Array.isArray(config) ? config : [config]) || []
const when = (condition, config, negativeConfig) => condition ? ensureArray(config) : ensureArray(negativeConfig)

View File

@@ -6,7 +6,8 @@ var extractCSS = new ExtractTextPlugin('vendor.css');
module.exports = ({ prod } = {}) => { module.exports = ({ prod } = {}) => {
const isDevBuild = !prod; const isDevBuild = !prod;
return { return [{
stats: { modules: false },
resolve: { resolve: {
extensions: ['.js'] extensions: ['.js']
}, },
@@ -51,5 +52,5 @@ module.exports = ({ prod } = {}) => {
].concat(isDevBuild ? [] : [ ].concat(isDevBuild ? [] : [
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } })
]) ])
} }]
}; };