Created
January 18, 2019 00:43
-
-
Save theKashey/0477957a6f284985e3d6a4d6c1b7d320 to your computer and use it in GitHub Desktop.
webpack + hot loader + ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* eslint-disable */ | |
const path = require('path') | |
const webpack = require('webpack') | |
const HtmlWebpackPlugin = require('html-webpack-plugin') | |
const sassRegex = /\.(scss|sass)$/; | |
const getStyleLoaders = (cssOptions, preProcessor) => { | |
const loaders = [ | |
require.resolve('style-loader'), | |
{ | |
loader: require.resolve('css-loader'), | |
options: cssOptions, | |
}, | |
{ | |
// Options for PostCSS as we reference these options twice | |
// Adds vendor prefixing based on your specified browser support in | |
// package.json | |
loader: require.resolve('postcss-loader'), | |
options: { | |
// Necessary for external CSS imports to work | |
// https://github.com/facebook/create-react-app/issues/2677 | |
ident: 'postcss', | |
plugins: () => [ | |
require('postcss-flexbugs-fixes'), | |
require('postcss-preset-env')({ | |
autoprefixer: { | |
flexbox: 'no-2009', | |
}, | |
stage: 3, | |
}), | |
], | |
}, | |
}, | |
]; | |
if (preProcessor) { | |
loaders.push(require.resolve(preProcessor)); | |
} | |
return loaders; | |
}; | |
module.exports = { | |
mode: 'development', | |
entry: ['./src/index.tsx'], | |
output: { | |
path: path.join(__dirname, 'dist'), | |
filename: '[name].js', | |
}, | |
devtool: false, | |
resolve: { | |
extensions: ['.ts', '.tsx', '.js', '.jsx'], | |
}, | |
module: { | |
rules: [ | |
{ | |
test: sassRegex, | |
use: getStyleLoaders({ importLoaders: 2 }, 'sass-loader'), | |
}, | |
{ | |
test: /\.(j|t)sx?$/, | |
exclude: /node_modules/, | |
use: { | |
loader: 'babel-loader', | |
options: { | |
cacheDirectory: true, | |
babelrc: false, | |
presets: [ | |
[ | |
'@babel/preset-env', | |
{ targets: { browsers: 'last 2 versions' } }, // or whatever your project requires | |
], | |
'@babel/preset-typescript', | |
'@babel/preset-react', | |
], | |
plugins: [ | |
// plugin-proposal-decorators is only needed if you're using experimental decorators in TypeScript | |
['@babel/plugin-proposal-decorators', { legacy: true }], | |
['@babel/plugin-proposal-class-properties', { loose: true }], | |
'react-hot-loader/babel', | |
], | |
}, | |
}, | |
}, | |
], | |
}, | |
plugins: [ | |
new webpack.NamedModulesPlugin(), | |
new HtmlWebpackPlugin(), | |
], | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment