2016-08-22 6 views
1

유니버설 자바 스크립트 응용 프로그램 용 Webpack 빌드가 있습니다. 모든 node_modules를 미리 빌드하기 위해 DLL 플러그인을 사용하고 있습니다. 나는 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 

웹팩 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", 
    ... } 

주의하는 것이 중요하다면 당신 경우 constants-browserify 모듈을 직접 설치하지 않았다면, 의존성으로 표시 한 모듈을 찾아야합니다. 당신이 말한대로 당신이 .json 파일의 로더를 지정해야합니다 다음 모듈을로드하려면

또는, 그리고, 그 DllPlugin 구문 분석을 시도 :

장소 :

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

inside of your

module.exports = { ... } 

이렇게하면 WebPack이 .json 파일을 올바르게 구문 분석 할 수 있습니다.

+0

나는 excludes 배열에 넣어 종속성을 쫓아 내려고했습니다. 너무 오래 걸리고 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 플러그인 구성 IgnorePlugin 또는 ignore-loader

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

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

관련 문제