Skip to content

Instantly share code, notes, and snippets.

@vitallium
Last active January 31, 2017 10:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vitallium/b51a057b1c6d1eb6d0fdba7f690527d7 to your computer and use it in GitHub Desktop.
Save vitallium/b51a057b1c6d1eb6d0fdba7f690527d7 to your computer and use it in GitHub Desktop.
TS + WebPack2
import * as React from "react";
import * as ReactDOM from "react-dom";
import { browserHistory, IndexRedirect, IndexRoute, Route, Router } from "react-router";
import { App } from "./src/Components";
import * as CommonActionCreators from "./src/ActionCreators";
ReactDOM.render((
<Router history={browserHistory}>
</Router>
), document.getElementById("app"));
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"declaration": false,
"noImplicitAny": false,
"removeComments": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"isolatedModules": false,
"noLib": false,
"preserveConstEnums": true,
"jsx": "react",
"sourceMap": true,
"importHelpers": true,
"lib": [ "es6", "dom" ]
},
"awesomeTypescriptLoaderOptions": {
"forkChecker": true
},
"filesGlob": [
"front/**/*.ts",
"front/**/*.tsx"
],
"exclude": [
"node_modules"
]
}
import "@blueprintjs/core";
import "axios";
import "class-transformer";
import "d3";
import "fbemitter";
import "flux";
import "lodash-es";
import "moment";
import "react";
import "react-dom";
import "react-proxy";
import "react-router";
import "reflect-metadata";
import "tslib";
const path = require('path');
const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const nodeEnv = process.env.NODE_ENV || 'development';
const extractSass = new ExtractTextPlugin({
filename: '[name].[contenthash].css',
disable: nodeEnv === 'development'
});
module.exports = {
context: path.resolve(__dirname),
entry: {
app: './Main.tsx',
vendor: './Vendor.ts',
},
output: {
filename: '[name].[hash].bundle.js',
chunkFilename: '[id].[hash].chunk.js',
path: path.join(__dirname, '../public/webpack'),
publicPath: '/',
},
module: {
rules: [
{
test: /\.ts(x?)$/,
exclude: [/node_modules/],
use: [
{
loader: 'react-hot-loader/webpack',
},
{
loader: 'awesome-typescript-loader',
},
],
},
{
test: /\.scss$/,
loader: extractSass.extract({
loader: [{
loader: 'css-loader',
}, {
loader: 'sass-loader',
}],
fallbackLoader: 'style-loader',
}),
},
],
},
resolve: {
modules: [
'node_modules',
path.resolve(__dirname),
],
descriptionFiles: ['package.json'],
extensions: ['.ts', '.tsx', '.js', '.jsx'],
moduleExtensions: ['-loader']
},
plugins: [
new webpack.NoEmitOnErrorsPlugin(),
new webpack.optimize.CommonsChunkPlugin({
name: ['app', 'vendor']
}),
new webpack.DefinePlugin({
'process.env': { NODE_ENV: JSON.stringify(nodeEnv) }
}),
new webpack.NamedModulesPlugin(),
extractSass,
],
};
const webpack = require('webpack');
const webpackMerge = require('webpack-merge');
const DashboardPlugin = require('webpack-dashboard/plugin');
const Visualizer = require('webpack-visualizer-plugin');
const path = require('path');
let commonConfig = require('./webpack.config.js');
let config = {
entry: {
app: [
'react-hot-loader/patch',
'./Main.tsx',
],
vendor: './Vendor.ts',
},
output: {
filename: '[name].bundle.js',
publicPath: 'http://localhost:8080/',
},
devtool: 'cheap-eval-source-map',
devServer: {
contentBase: path.resolve(__dirname, '../public/webpack'),
historyApiFallback: true,
port: 8080,
compress: false,
hot: true,
headers: { 'Access-Control-Allow-Origin': '*' },
stats: {
assets: true,
children: false,
chunks: false,
hash: false,
modules: false,
publicPath: false,
timings: true,
version: false,
warnings: true,
colors: true,
},
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new DashboardPlugin(),
new Visualizer(),
],
performance: {
hints: false,
},
};
module.exports = webpackMerge.strategy({
entry: 'replace',
})(commonConfig, config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment