mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-17 02:54:21 +08:00
* Added ability to specify output path for bundles and assets with `ng build` commands. * Command is specified by using the `--output-path` flag.
85 lines
2.6 KiB
TypeScript
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
|
|
}
|
|
}
|
|
};
|