现在我设法设置了一个webpack配置和webpack-dev-server(hotload),同时管理我所有的子项目/插件。
但是,我希望能够解析每个子项目的文件夹,例如/components
,以避免长的相对路径。这可能吗?
我有以下文件夹结构
-/ MyProject
-/ node_modules
-/ plugin1
-/ node_modules
- package.json
...
-/ plugin2
-/ plugin3
-/ shared (styles etc)
- webpack.config.js
- package.json
我的webpack conf:
var webpack = require(' webpack'); var path = require(' path'); var ExtractTextPlugin = require(' extract-text-webpack-plugin')
var env = process.env.NODE_ENV; var isProduction = env ===' production' var host =' http://localhost:4000&#39 ;; var socketHost =' ws:// localhost:4000';
module.exports = {
devtool: 'source-map',
entry: {
script: ['webpack-hot-middleware/client', './js/script/src/index.js'],
app: ['webpack-hot-middleware/client', './js/site/index.js'],
},
output: {
path: path.join(__dirname , 'dist'),
filename: '[name].js',
publicPath: '/static/'
},
resolve: {
root: path.resolve(__dirname),
alias: {
styles: path.join(__dirname, 'styles'),
app: path.join(__dirname, 'js', 'site'),
script: path.join(__dirname, 'js', 'script'),
}
},
module: {
loaders: [
{
test: /\.jsx?$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.scss$/,
loaders: ["style", "css", "sass"]
},
{
test: /\.(otf|eot|svg|ttf|woff|woff2)(\?.+)$/,
loader: 'url-loader?limit=8192',
include: /node_modules/
}
]
},
plugins: [
new webpack.DefinePlugin({ PRODUCTION: false, APP_HOST: JSON.stringify(host), WS_HOST: JSON.stringify(socketHost) }),
new webpack.optimize.OccurenceOrderPlugin(), // recommanded by webpack
// new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin(), // recommanded by webpack
// new ExtractTextPlugin('bundle.css')
]
};