Skip to content

Instantly share code, notes, and snippets.

@KingDarBoja
Created November 8, 2019 13:19
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 KingDarBoja/940125eaa23edecee2a8a173f1938cf4 to your computer and use it in GitHub Desktop.
Save KingDarBoja/940125eaa23edecee2a8a173f1938cf4 to your computer and use it in GitHub Desktop.
Basic example of webpack configuration file using Typescript for any ng-toolkit generated project.
// Work around for https://github.com/angular/angular-cli/issues/7200
import path from 'path';
import webpack from 'webpack';
const config: webpack.Configuration = {
mode: 'none',
entry: {
// This is our Express server for Dynamic universal
server: './server.ts',
prerender: './prerender.ts',
},
target: 'node',
resolve: { extensions: ['.ts', '.js'] },
optimization: {
minimize: false,
},
output: {
libraryTarget: 'commonjs2',
// Puts the output at the root of the dist folder
path: path.resolve(process.cwd(), 'dist'),
filename: '[name].js',
},
module: {
rules: [
{ test: /\.ts$/, loader: 'ts-loader' },
{
// Mark files inside `@angular/core` as using SystemJS style dynamic imports.
// Removing this will cause deprecation warnings to appear.
test: /(\\|\/)@angular(\\|\/)core(\\|\/).+\.js$/,
parser: { system: true },
},
],
},
plugins: [
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?angular(\\|\/)core(.+)?/,
path.join(__dirname, 'src'), // location of your src
{}, // a map of your routes
),
new webpack.ContextReplacementPlugin(
// fixes WARNING Critical dependency: the request of a dependency is an expression
/(.+)?express(\\|\/)(.+)?/,
path.join(__dirname, 'src'),
{},
),
],
};
export default config;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment