This template is meant to be a good starting point for anyone who wants to start building modern web apps.
- Builds clientside web applications with webpack and babel.
- Includes a cachebreaker hash to the output files.
- Treeshaking with webpack.
- Splits libraries from application code to improve build times.
- Automatic splitting of webpacked files to improve load times at runtime.
- Supports css and scss.
- Also builds seperate css, fonts and other files.
(Either from seperate entry points for css, or from
requirestatements in JavaScript code.) - A webserver with hot reload when developing your app.
- No need install any global npm packages!
- This template will act as a starting point for creating web apps.
- The project template should include a development web server.
- The template should contain as few devDependencies as possible, so that it will be easy to evolve the build configuration as different packages are updated or made obsolete.
- Copy the files and structure of this project.
(If you use
git cloneyou would probably want to remove the.gitdirectory before initializing your new repo.) - Modify
package.jsonto reflect the correct names. - Run
npm updateto load dependencies. - Create your app in the
srcfolder. - Run
npm startto start the dev-server. Navigate to (localhost:8080)[http://localhost:8080] - Build by running
npm run build. (npx webpackalso works, but doesn't clean out thedistdirectory first.)
- Create a folder:
src. - Copy five files:
webpack.*.config.js(=5 files), and.gitignoreandpackage.json. - Modify
package.json, and runnpm installto pull inn all dependencies.
- Compilation plugins should primarily be added to
babelrcfile. - Loaders and plugins that are common to all build configuration should be added to
webpack.common.config.js webpack.development.config.jsandwebpack.production.config.jscontain additional configuration that is specific for the different builds.webpack.serve.configextends the development configuration, adding configuration relevant towebpack-dev-server.
Run on the commandline:
npm install -D typescript awesome-typescript-loader source-map-loaderAdd the following object to rules in webpack.common.config:
{
test: /\.ts$/,
use: "awesome-typescript-loader"
}- Optionally, change the entry point (in webpack.common.config) to "index.ts"
- Optionally, add
.tsextention to theresolveelement so that typescript files can be required without the.tsextension:
resolve: {
extensions: ['.js', '.ts']
}Run on the commandline:
npm install -D @babel/preset-react
npm install -S react react-domAdd "react" to the presets array in the .babelrc file. If you haven't modified .babelrc yet, it will look like this:
{
"presets": [
["@babel/preset-env", {"modules": false}],
["@babel/preset-react"]
],
"plugins": [
]
}- Optionally, change the entry point (in webpack.common.config) to "index.jsx"
- Optionally, add
.jsxextention to theresolveelement so that jsx files can be required without the.jsxextension:
resolve: {
extensions: ['.js', '.jsx']
}Adding the ng-annotate-loader saves you from doubly declaring your angular dependency injections.
Run on the commandline:
npm install -D babel-plugin-angularjs-annotate
npm install -S angularAdd "angularjs-annotate" to the plugins array in the .babelrc file. If you haven't modified .babelrc yet, it will look like this:
{
"presets": [
["@babel/preset-env", {"modules": false}],
],
"plugins": [
["angularjs-annotate"]
]
}