我在app/components/
中定義了一些React組件。我設置一些別名的WebPack這樣的:Webpack別名:「./{path}」和「{path}」有什麼區別?
//webpack.conf.js
module.exports = {
entry: './app/app.jsx',
output: {
path: __dirname,
filename: './public/bundle.js'
},
resolve: {
root: __dirname,
alias: {
Main: 'app/components/Main.jsx',
Nav: 'app/components/Nav.jsx',
Weather: 'app/components/Weather.jsx',
About: 'app/components/About.jsx'
},
extensions: ['', '.js', '.jsx']
},
module: {
loaders: [
{
loader: 'babel-loader',
query: {
presets: ['react', 'es2015', 'stage-0']
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/
}
]
}
};
我的問題是:爲什麼所有的別名開始'app'
而不是'./app'
?當我將別名更改爲以'./'
開頭(因爲我認爲它們是相同的),webpack抱怨Module not found: Error: Cannot resolve...
,所以它看起來並不相同。
爲什麼要求entry
和output.filename
,他們確實需要'./'
?是因爲resolve.root: __dirname
? __dirname
(均在resolve and in
輸出)的目的是什麼?
這[link](http://webpack.github.io/docs/configuration.html#resolve-alias)很棒。謝謝 –
高興地幫助! :)。如果您發現它有用,請接受答案。 –