Created
March 21, 2018 18:01
-
-
Save jatovar/b2c038efc7c9bbd0aca3642025677160 to your computer and use it in GitHub Desktop.
Webpack for parsing CLDR file with globalize :)
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
const path = require('path'); | |
const webpack = require('webpack'); | |
const merge = require('webpack-merge'); | |
const AotPlugin = require('@ngtools/webpack').AotPlugin; | |
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin; | |
module.exports = (env) => { | |
// Configuration in common to both client-side and server-side bundles | |
const isDevBuild = !(env && env.prod); | |
const sharedConfig = { | |
stats: { modules: false }, | |
context: __dirname, | |
resolve: { | |
alias: { | |
globalize$: path.resolve(__dirname, 'node_modules/globalize/dist/globalize.js'), | |
globalize: path.resolve(__dirname, 'node_modules/globalize/dist/globalize'), | |
cldr$: path.resolve(__dirname, 'node_modules/cldrjs/dist/cldr.js'), | |
cldr: path.resolve(__dirname, 'node_modules/cldrjs/dist/cldr') | |
}, | |
extensions: [ '.js', '.ts', '.json' ] | |
}, | |
output: { | |
filename: '[name].js', | |
publicPath: 'dist/' // Webpack dev middleware, if enabled, handles requests for this URL prefix | |
}, | |
module: { | |
rules: [ | |
{ test: /\.ts$/, use: isDevBuild ? ['awesome-typescript-loader?silent=true', 'angular2-template-loader', 'angular2-router-loader'] : '@ngtools/webpack' }, | |
{ test: /\.html$/, use: 'html-loader?minimize=false' }, | |
{ test: /\.css$/, use: [ 'to-string-loader', isDevBuild ? 'css-loader' : 'css-loader?minimize' ] }, | |
{ test: /\.(png|jpg|jpeg|gif|svg)$/, use: 'url-loader?limit=25000' }, | |
{ test: /\.json$/, loader: 'json-loader'} | |
] | |
}, | |
plugins: [new CheckerPlugin()] | |
}; | |
// Configuration for client-side bundle suitable for running in browsers | |
const clientBundleOutputDir = './wwwroot/dist'; | |
const clientBundleConfig = merge(sharedConfig, { | |
entry: { 'main-client': './ClientApp/boot.browser.ts' }, | |
output: { path: path.join(__dirname, clientBundleOutputDir) }, | |
plugins: [ | |
new webpack.DllReferencePlugin({ | |
context: __dirname, | |
manifest: require('./wwwroot/dist/vendor-manifest.json') | |
}) | |
].concat(isDevBuild ? [ | |
// Plugins that apply in development builds only | |
new webpack.SourceMapDevToolPlugin({ | |
filename: '[file].map', // Remove this line if you prefer inline source maps | |
moduleFilenameTemplate: path.relative(clientBundleOutputDir, '[resourcePath]') // Point sourcemap entries to the original file locations on disk | |
}) | |
] : [ | |
// Plugins that apply in production builds only | |
new webpack.optimize.UglifyJsPlugin(), | |
new AotPlugin({ | |
tsConfigPath: './tsconfig.json', | |
entryModule: path.join(__dirname, 'ClientApp/app/app.browser.module#AppModule'), | |
exclude: ['./**/*.server.ts'] | |
}) | |
]) | |
}); | |
// Configuration for server-side (prerendering) bundle suitable for running in Node | |
const serverBundleConfig = merge(sharedConfig, { | |
resolve: { mainFields: ['main'] }, | |
entry: { 'main-server': './ClientApp/boot.server.ts' }, | |
plugins: [ | |
new webpack.DllReferencePlugin({ | |
context: __dirname, | |
manifest: require('./ClientApp/dist/vendor-manifest.json'), | |
sourceType: 'commonjs2', | |
name: './vendor' | |
}) | |
].concat(isDevBuild ? [] : [ | |
// Plugins that apply in production builds only | |
new AotPlugin({ | |
tsConfigPath: './tsconfig.json', | |
entryModule: path.join(__dirname, 'ClientApp/app/app.server.module#AppModule'), | |
exclude: ['./**/*.browser.ts'] | |
}) | |
]), | |
output: { | |
libraryTarget: 'commonjs', | |
path: path.join(__dirname, './ClientApp/dist') | |
}, | |
target: 'node', | |
devtool: 'inline-source-map' | |
}); | |
return [clientBundleConfig, serverBundleConfig]; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment