Skip to content

Instantly share code, notes, and snippets.

@serbanghita
Created January 4, 2018 10:00
Show Gist options
  • Save serbanghita/8a81431d29ee692fe12bb91467a39527 to your computer and use it in GitHub Desktop.
Save serbanghita/8a81431d29ee692fe12bb91467a39527 to your computer and use it in GitHub Desktop.
Webpack with Dev Server
./node_modules/.bin/webpack-dev-server --open --watch-content-base
// Read: https://github.com/webpack/webpack-dev-server/issues/155
// Read: https://github.com/gaearon/react-hot-loader/blob/master/docs/Troubleshooting.md#syntax-error-unexpected-token-
let path = require("path");
const { CheckerPlugin } = require("awesome-typescript-loader");
module.exports = {
entry: "./src/index.tsx",
output: {
filename: "website.min.js",
path: path.resolve(__dirname, "dist/js"),
publicPath: "/js/"
},
// Enable sourcemaps for debugging webpack's output.
devtool: "cheap-eval-source-mapService",
devServer: {
contentBase: "dist",
watchContentBase: true
},
watch: false,
node: {
__dirname: true
},
resolve: {
// Add '.ts' and '.tsx' as resolvable extensions.
extensions: [".ts", ".tsx", ".js", ".json"]
},
module: {
rules: [
// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
{ test: /\.tsx$/, loader: "awesome-typescript-loader" },
// All output '.js' files will have any sourcemaps re-processed by 'source-mapService-loader'.
{ enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
]
},
plugins: [
new CheckerPlugin()
]
// When importing a module whose path matches one of the following, just
// assume a corresponding global variable exists and use that instead.
// This is important because it allows us to avoid bundling all of our
// dependencies, which allows browsers to cache those libraries between builds.
// externals: {
// "react": "React",
// "react-dom": "ReactDOM"
// },
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment