Update ReactSpa to Webpack 2 (plus awesome-typescript-loader)

This commit is contained in:
SteveSandersonMS
2017-01-27 14:55:43 +00:00
parent be3fb6e876
commit bdd7cfd38b
3 changed files with 87 additions and 83 deletions

View File

@@ -7,8 +7,9 @@
"@types/react": "^0.14.38", "@types/react": "^0.14.38",
"@types/react-dom": "^0.14.17", "@types/react-dom": "^0.14.17",
"@types/react-router": "^2.0.38", "@types/react-router": "^2.0.38",
"aspnet-webpack": "^1.0.17", "aspnet-webpack": "^1.0.27",
"aspnet-webpack-react": "^1.0.2", "aspnet-webpack-react": "^1.0.4",
"awesome-typescript-loader": "3.0.0-beta.13 || ^3.0.0",
"babel-core": "^6.17.0", "babel-core": "^6.17.0",
"babel-loader": "^6.2.5", "babel-loader": "^6.2.5",
"babel-preset-es2015": "^6.16.0", "babel-preset-es2015": "^6.16.0",
@@ -16,7 +17,7 @@
"bootstrap": "^3.3.6", "bootstrap": "^3.3.6",
"css-loader": "^0.25.0", "css-loader": "^0.25.0",
"event-source-polyfill": "^0.0.7", "event-source-polyfill": "^0.0.7",
"extract-text-webpack-plugin": "^1.0.1", "extract-text-webpack-plugin": "^2.0.0-rc",
"file-loader": "^0.9.0", "file-loader": "^0.9.0",
"isomorphic-fetch": "^2.2.1", "isomorphic-fetch": "^2.2.1",
"jquery": "^2.2.1", "jquery": "^2.2.1",
@@ -25,10 +26,9 @@
"react-dom": "^15.3.2", "react-dom": "^15.3.2",
"react-router": "^2.8.1", "react-router": "^2.8.1",
"style-loader": "^0.13.1", "style-loader": "^0.13.1",
"ts-loader": "^0.8.2",
"typescript": "^2.0.3", "typescript": "^2.0.3",
"url-loader": "^0.5.7", "url-loader": "^0.5.7",
"webpack": "^1.13.2", "webpack": "^2.2.0",
"webpack-hot-middleware": "^2.12.2" "webpack-hot-middleware": "^2.12.2"
} }
} }

View File

@@ -1,42 +1,44 @@
var isDevBuild = process.argv.indexOf('--env.prod') < 0; const path = require('path');
var path = require('path'); const webpack = require('webpack');
var webpack = require('webpack'); const ExtractTextPlugin = require('extract-text-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin'); const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const bundleOutputDir = './wwwroot/dist';
var bundleOutputDir = './wwwroot/dist'; module.exports = (env) => {
module.exports = { const isDevBuild = !(env && env.prod);
devtool: isDevBuild ? 'inline-source-map' : null, return [{
entry: { 'main': './ClientApp/boot.tsx' }, stats: { modules: false },
resolve: { extensions: [ '', '.js', '.jsx', '.ts', '.tsx' ] }, entry: { 'main': './ClientApp/boot.tsx' },
output: { resolve: { extensions: [ '.js', '.jsx', '.ts', '.tsx' ] },
path: path.join(__dirname, bundleOutputDir), output: {
filename: '[name].js', path: path.join(__dirname, bundleOutputDir),
publicPath: '/dist/' filename: '[name].js',
}, publicPath: '/dist/'
module: { },
loaders: [ module: {
{ test: /\.ts(x?)$/, include: /ClientApp/, loader: 'babel-loader' }, rules: [
{ test: /\.tsx?$/, include: /ClientApp/, loader: 'ts-loader', query: { silent: true } }, { test: /\.ts(x?)$/, include: /ClientApp/, use: 'babel-loader' },
{ test: /\.css$/, loader: isDevBuild ? 'style-loader!css-loader' : ExtractTextPlugin.extract(['css-loader']) }, { test: /\.tsx?$/, include: /ClientApp/, use: 'awesome-typescript-loader?silent=true' },
{ test: /\.(png|jpg|jpeg|gif|svg)$/, loader: 'url-loader', query: { limit: 25000 } }, { test: /\.css$/, loader: isDevBuild ? 'style-loader!css-loader' : ExtractTextPlugin.extract({ loader: 'css-loader' }) },
{ test: /\.json$/, loader: 'json-loader' } { test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }
] ]
}, },
plugins: [ plugins: [
new webpack.DllReferencePlugin({ new CheckerPlugin(),
context: __dirname, new webpack.DllReferencePlugin({
manifest: require('./wwwroot/dist/vendor-manifest.json') context: __dirname,
}) manifest: require('./wwwroot/dist/vendor-manifest.json')
].concat(isDevBuild ? [ })
// Plugins that apply in development builds only ].concat(isDevBuild ? [
new webpack.SourceMapDevToolPlugin({ // Plugins that apply in development builds only
filename: '[file].map', // Remove this line if you prefer inline source maps new webpack.SourceMapDevToolPlugin({
moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk filename: '[file].map', // Remove this line if you prefer inline source maps
}) moduleFilenameTemplate: path.relative(bundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk
] : [ })
// Plugins that apply in production builds only ] : [
new webpack.optimize.OccurenceOrderPlugin(), // Plugins that apply in production builds only
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }), new webpack.optimize.UglifyJsPlugin(),
new ExtractTextPlugin('site.css') new ExtractTextPlugin('site.css')
]) ])
}];
}; };

View File

@@ -1,40 +1,42 @@
var isDevBuild = process.argv.indexOf('--env.prod') < 0; const path = require('path');
var path = require('path'); const webpack = require('webpack');
var webpack = require('webpack'); const ExtractTextPlugin = require('extract-text-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var extractCSS = new ExtractTextPlugin('vendor.css');
module.exports = { module.exports = (env) => {
resolve: { const extractCSS = new ExtractTextPlugin('vendor.css');
extensions: [ '', '.js' ] const isDevBuild = !(env && env.prod);
}, return [{
module: { stats: { modules: false },
loaders: [ resolve: {
{ test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, loader: 'url-loader?limit=100000' }, extensions: [ '.js' ]
{ test: /\.css(\?|$)/, loader: extractCSS.extract(['css-loader']) } },
] module: {
}, rules: [
entry: { { test: /\.(png|woff|woff2|eot|ttf|svg)(\?|$)/, use: 'url-loader?limit=100000' },
vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'event-source-polyfill', 'isomorphic-fetch', 'react', 'react-dom', 'react-router', 'style-loader', 'jquery'], { test: /\.css(\?|$)/, use: extractCSS.extract(['css-loader']) }
}, ]
output: { },
path: path.join(__dirname, 'wwwroot', 'dist'), entry: {
publicPath: '/dist/', vendor: ['bootstrap', 'bootstrap/dist/css/bootstrap.css', 'event-source-polyfill', 'isomorphic-fetch', 'react', 'react-dom', 'react-router', 'style-loader', 'jquery'],
filename: '[name].js', },
library: '[name]_[hash]', output: {
}, path: path.join(__dirname, 'wwwroot', 'dist'),
plugins: [ publicPath: '/dist/',
extractCSS, filename: '[name].js',
new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable) library: '[name]_[hash]',
new webpack.optimize.OccurenceOrderPlugin(), },
new webpack.DllPlugin({ plugins: [
path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'), extractCSS,
name: '[name]_[hash]' new webpack.ProvidePlugin({ $: 'jquery', jQuery: 'jquery' }), // Maps these identifiers to the jQuery package (because Bootstrap expects it to be a global variable)
}), new webpack.DllPlugin({
new webpack.DefinePlugin({ path: path.join(__dirname, 'wwwroot', 'dist', '[name]-manifest.json'),
'process.env.NODE_ENV': isDevBuild ? '"development"' : '"production"' name: '[name]_[hash]'
}) }),
].concat(isDevBuild ? [] : [ new webpack.DefinePlugin({
new webpack.optimize.UglifyJsPlugin({ compress: { warnings: false } }) 'process.env.NODE_ENV': isDevBuild ? '"development"' : '"production"'
]) })
].concat(isDevBuild ? [] : [
new webpack.optimize.UglifyJsPlugin()
])
}];
}; };