是的 - 具有所有其他文件作为依赖项的文件 - 是一个很好的条目候选者,您还可以拥有多个文件作为条目来拆分 verdor/您自己的代码以分隔 js,这里是示例配置(假设您将使用 webpack2):
https://github.com/wkwiatek/angular2-webpack2/blob/master/webpack.config.js
这是 webpack 2 配置的工作版本
module.exports = {
module: {
rules: [
{
// Allows me to
// @Component({
// styles: [require('./styles.scss')]
// })
test: /\.scss$/,
use: [
{ loader: "raw-loader" },
{ loader: "sass-loader" }
]
},
{
// bundle external dependencies to separate file
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: "style-loader",
use: "css-loader"
})
},
{
// ts files compilation
test: /\.tsx?$/,
loader: 'ts-loader',
exclude: /node_modules/,
},
{
// Allows me to
// @Component({
// template: require('./template.html')
// })
test: /\.html?$/,
loader: 'html-loader'
},
{
enforce: 'pre',
test: /\.tsx?$/,
use: "source-map-loader"
},
// stuffs for correct font-awesome loading
{ test: /\.woff(2)?(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "url-loader?limit=10000&mimetype=application/font-woff" },
{ test: /\.(ttf|eot|svg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader: "file-loader" }
]
},
plugins: [
new ExtractTextPlugin("vendor.css"),
new webpack.optimize.OccurrenceOrderPlugin(),
// inject vendor.css and index.js links into index.html
new HtmlWebpackPlugin({
template: conf.path.src('index.html')
}),
// workaround for disable warning about critical dependency
new webpack.ContextReplacementPlugin(
/angular(\\|\/)core(\\|\/)(esm(\\|\/)src|src)(\\|\/)linker/,
conf.paths.src
)
],
devtool: 'source-map',
output: {
path: path.join(process.cwd(), conf.paths.tmp),
filename: 'index.js'
},
resolve: {
extensions: [
'.js',
'.ts'
]
},
// entry point
entry: `./src/index`,
};