2017-02-01 5 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のは、その後のために意図されているどのような 'exclude'と' include'オプションあなたの 'index.js' – cyrix

+0

にインポートして使用しているものを除外することはできません。完全にあなたがmodule.noParseオプションを使用する必要がバンドルから何かを除外するには? – Sergei

+1

あなたはここで良い説明を読むことができます:http://stackoverflow.com/questions/37823764/how-include-and-exclude-works-in-webpack-loaderあなたは '.jsx'をテストしていますが、あなたのファイルは'js' – cyrix

答えて

関連する問題