2017-02-01 123 views
1

的WebPack 2.2.0包含/排除不工作

包括我/在我的配置排除文件/文件夾,但保留的WebPack是捆綁排除:

的文件夾結構

src/ 
    index.js // entry point 
server/ 
    test.js // file for testing 
build/ 

webpack.config.js

const path = require('path') 
const SRC = path.resolve(process.cwd(), './src') 
const BUILD = path.resolve(process.cwd(), './build') 

module.exports = { 
    context: SRC, 
    entry: { 
    main: './' 
    }, 
    output: { 
    path: BUILD, 
    filename: '[name].bundle.js', 
    publicPath: '/assets/' 
    }, 
    module: { 
    rules: [{ 
     test: /\.jsx?/, 
     include: SRC, 
     exclude: path.resolve(process.cwd(), './server’), // even explicit excluding changes nothing 
     loader: 'babel-loader' 
    }] 
    } 
} 

./src/index.js

import func from ‘../server/test.js’ // this must not be imported 
func() // working 

./server/test.js

export default function() { console.log(`I’m in the bundle`) } // this is being executed 

我看到消息在瀏覽器控制檯。

+1

Webpack無法排除您正在導入並在您的「index.js」中使用的內容 – cyrix

+0

然後,將使用「exclude」和「include」選項? – Sergei

+1

你可以在這裏閱讀一個很好的解釋:http://stackoverflow.com/questions/37823764/how-include-and-exclude-works-in-webpack-loader順便說一句,你正在測試'.jsx',但你的文件是'js' – cyrix

回答