我的Webpack在一个index.js中编译我的所有项目。我该怎么做才能在" index.js"中获取javascript代码和" style / index.css"中的css代码? 我的webpack.config.js:
`
var path = require(' path');
module.exports = {
entry: './entry.js',
output: {
filename: 'testApp/www/index.js'
},
resolve: {
extensions: ['.js', '.jsx', '.json']
},
module: {
loaders: [
{ test: /\.jsx?$/,
loader: 'babel-loader',
include: path.resolve(__dirname,` "app"),
query:
{
presets:['react', 'es2015', 'stage-0']
}
},
{
test: /\.scss$/,
loader: 'style-loader!css-loader!sass-loader'
}
]
}
};
`
答案 0 :(得分:0)
您可以使用ExtractTextPlugin
在控制台上运行npm install --save-dev extract-text-webpack-plugin
在你的webpack.config.js
中module.exports = {
entry: './entry.js',
output: {
filename: 'testApp/www/index.js'
},
resolve: {
extensions: ['.js', '.jsx', '.json']
},
module: {
loaders: [
{ test: /\.jsx?$/,
loader: 'babel-loader',
include: path.resolve(__dirname, "app"),
query:
{
presets:['react', 'es2015', 'stage-0']
}
},
{
test: /\.scss$/,
loader: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
}
]
},
plugins: [
new ExtractTextPlugin('style/index.css')
],
};