angular-cli/addon/ng2/models/webpack-build-common.ts
Carlos Sanz García c58c5b3ef9 This should fix the missing option '--output-path' on webpack. (#1627)
* Added ability to specify output path for bundles and assets with `ng build` commands. 
* Command is specified by using the `--output-path` flag.
2016-08-17 11:17:23 -05:00

85 lines
2.6 KiB
TypeScript

import * as path from 'path';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
import * as HtmlWebpackPlugin from 'html-webpack-plugin';
import * as webpack from 'webpack';
import { ForkCheckerPlugin } from 'awesome-typescript-loader';
import { CliConfig } from './config';
export function getWebpackCommonConfig(projectRoot: string, sourceDir: string, outputDir: string) {
let outputPath: string = path.resolve(projectRoot, outputDir);
return {
devtool: 'source-map',
resolve: {
extensions: ['', '.ts', '.js'],
root: path.resolve(projectRoot, `./${sourceDir}`)
},
context: path.resolve(__dirname, './'),
entry: {
main: [path.resolve(projectRoot, `./${sourceDir}/main.ts`)],
polyfills: path.resolve(projectRoot, `./${sourceDir}/polyfills.ts`)
},
output: {
path: outputPath,
filename: '[name].bundle.js'
},
module: {
loaders: [
{
test: /\.ts$/,
loaders: [
{
loader: 'awesome-typescript-loader',
query: {
useForkChecker: true,
tsconfig: path.resolve(projectRoot, `./${sourceDir}/tsconfig.json`)
}
},
{
loader: 'angular2-template-loader'
}
],
exclude: [/\.(spec|e2e)\.ts$/]
},
{ test: /\.json$/, loader: 'json-loader'},
{ test: /\.css$/, loaders: ['raw-loader', 'postcss-loader'] },
{ test: /\.styl$/, loaders: ['raw-loader', 'postcss-loader', 'stylus-loader'] },
{ test: /\.less$/, loaders: ['raw-loader', 'postcss-loader', 'less-loader'] },
{ test: /\.scss$|\.sass$/, loaders: ['raw-loader', 'postcss-loader', 'sass-loader'] },
{ test: /\.(jpg|png)$/, loader: 'url-loader?limit=128000'},
{ test: /\.html$/, loader: 'raw-loader' }
]
},
plugins: [
new ForkCheckerPlugin(),
new HtmlWebpackPlugin({
template: path.resolve(projectRoot, `./${sourceDir}/index.html`),
chunksSortMode: 'dependency'
}),
new webpack.optimize.CommonsChunkPlugin({
name: ['polyfills']
}),
new webpack.optimize.CommonsChunkPlugin({
minChunks: Infinity,
name: 'inline',
filename: 'inline.js',
sourceMapFilename: 'inline.map'
}),
new CopyWebpackPlugin([{
context: path.resolve(projectRoot, './public'),
from: '**/*',
to: outputPath
}])
],
node: {
fs: 'empty',
global: 'window',
crypto: 'empty',
module: false,
clearImmediate: false,
setImmediate: false
}
}
};