首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Webpack DLL构建中不包括模块

Webpack DLL构建中不包括模块
EN

Stack Overflow用户
提问于 2016-08-22 15:20:23
回答 2查看 2.9K关注 0票数 2

我有一个Webpack构建的通用Javascript应用程序。我正在使用DLL插件预构建我所有的node_modules.我添加了一个库,它导致DLL构建出错(参见下面)。

我可能可以添加一个JSON加载程序来解决这个问题。但我根本不想在React代码中使用lib。我将它添加到我的排除列表中,但它仍然抛出一个错误。

以下是错误:

代码语言:javascript
复制
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构建脚本:

代码语言:javascript
复制
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
  ],
};

来自package.json的DLL插件配置:

代码语言:javascript
复制
"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"
  ]
},
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-08-29 15:28:47

注:这只适用于反应样板.

要将模块从DllPlugin中排除在外,您需要添加模块(或在排除数组中的依赖方处标记它的模块):

代码语言:javascript
复制
excludes = { 
  "constants-browserify",
  ... }

如果需要注意的是,如果没有直接安装常量-browserify模块,则需要找到标记为依赖项的模块。

或者,正如您所说的,如果您想加载模块,那么您需要为.json文件指定一个加载程序,DllPlugin正试图解析该文件:

地点:

代码语言:javascript
复制
module: {
  loaders: [
    {
      test: /\.json$/,
      loader: 'json-loader',
    }
  ],
},

在你的内心

代码语言:javascript
复制
module.exports = { ... }

这将允许WebPack正确地解析.json文件。

票数 0
EN

Stack Overflow用户

发布于 2016-08-22 17:03:42

我认为您可以使用IgnorePluginignore-loader排除某些模块。

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

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39083260

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档