2016-08-22 82 views
1

我爲通用JavaScript應用程序構建了一個Webpack。我正在使用DLL插件預先構建我的所有node_modules。我添加了一個導致DLL構建出錯的lib(請參見下文)。從Webpack DLL中排除模塊構建

我可以添加一個JSON加載器來解決這個問題。但是我根本不需要React代碼中的lib。我將它添加到我的排除列表中,但仍然出現錯誤。

這裏的錯誤:

Building the Webpack DLL... 
Hash: a69a927bfa72ddef88d5 
Version: webpack 2.1.0-beta.15 
Time: 7152ms 
         Asset  Size Chunks    Chunk Names 
reactBoilerplateDeps.dll.js 5.58 MB  0 [emitted] reactBoilerplateDeps 
chunk {0} reactBoilerplateDeps.dll.js (reactBoilerplateDeps) 5.07 MB [rendered] 
[1135] dll reactBoilerplateDeps 12 bytes {0} [built] 
    + 1137 hidden modules 

ERROR in ./~/constants-browserify/constants.json 
Module parse failed: /Users/steve/Projects/elucidate/node_modules/constants-browserify/constants.json Unexpected token (2:12) 
You may need an appropriate loader to handle this file type. 
| { 
| "O_RDONLY": 0, 
| "O_WRONLY": 1, 
| "O_RDWR": 2, 
@ ./~/graceful-fs/polyfills.js 2:16-36 

的WebPack DLL構建腳本:

"dllPlugin": { 
    "path": "node_modules/react-boilerplate-dlls", 
    "exclude": [ 
    "chalk", 
    "compression", 
    "cross-env", 
    "express", 
    "ip", 
    "minimist", 
    "sanitize.css", 
    "multiparty", 
    "cloudinary", 
    "winston", 
    "morgan", 
    "body-parser", 
    "request-promise", 
    "winston-graylog2", 
    "yauzl", 
    "busboy", 
    "graceful-fs" 
    ], 
    "include": [ 
    "core-js", 
    "lodash", 
    "eventsource-polyfill" 
    ] 
}, 

回答

0

注:這是才反應過來 - 樣板。

要排除從DllPlugin你需要添加模塊,該模塊(或具有它標誌着其在排除陣列取決於模塊):

excludes = { 
    "constants-browserify", 
    ... } 

如果重要的是要注意,如果你沒有直接安裝常量 - browserify模塊,您需要找到已標記爲依賴項的模塊。

或者,正如你說的,如果你想加載模塊,那麼你需要指定以.json文件加載器的DllPlugin試圖解析:

地點:

module: { 
    loaders: [ 
    { 
     test: /\.json$/, 
     loader: 'json-loader', 
    } 
    ], 
}, 

在你的內部

module.exports = { ... } 

這將允許WebPack正確解析.json文件。

+0

我試圖追逐依賴放入我的排除數組。這花了太長時間,並且將JSON加載器添加到DLL構建中。 – spdaly

1

我想你可以排除一些模塊:來自的package.json

const { join } = require('path'); 
const defaults = require('lodash/defaultsDeep'); 
const webpack = require('webpack'); 
const pkg = require(join(process.cwd(), 'package.json')); 
const dllPlugin = require('../config').dllPlugin; 

if (!pkg.dllPlugin) { process.exit(0); } 

const dllConfig = defaults(pkg.dllPlugin, dllPlugin.defaults); 
const outputPath = join(process.cwd(), dllConfig.path); 

module.exports = { 
    context: process.cwd(), 
    entry: dllConfig.dlls ? dllConfig.dlls : dllPlugin.entry(pkg), 
    devtool: 'eval', 
    output: { 
    filename: '[name].dll.js', 
    path: outputPath, 
    library: '[name]', 
    }, 
    node: { 
    fs: "empty", 
    }, 
    plugins: [ 
    new webpack.DllPlugin({ name: '[name]', path: join(outputPath, '[name].json') }), // eslint-disable-line no-new 
    ], 
}; 

DLL插件配置IgnorePluginignore-loader

https://webpack.github.io/docs/list-of-plugins.html#ignoreplugin

https://github.com/cherrry/ignore-loader