javascript - 使用 Extract Text Webpack 插件时出错

标签 javascript webpack extract-text-plugin

我对前端相当陌生,我一直在尝试学习 webpack。使用 Extract-Text-Webpack-Plugin 时遇到一些我似乎无法弄清楚的问题。对于这个主题的任何帮助,我将不胜感激。另外,欢迎任何建议/提示!

警告/错误

WARNING in ./~/chokidar/lib/fsevents-handler.js Module not found: Error: Cannot resolve module 'fsevents' in C:\Git\JNJ.Web\src\JNJ.Web.UI\client\node_modules\chokidar\lib @ ./~/chokidar/lib/fsevents-handler.js 7:17-36

ERROR in (webpack)/~/constants-browserify/constants.json Module parse failed: C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\constants-browserify\constants.json Unexpected token (2:12) You may need an appropriate loader to handle this file type. SyntaxError: Unexpected token (2:12) at Parser.pp$4.raise (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15) at Parser.pp.unexpected (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10) at Parser.pp.semicolon (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:581:61) at Parser.pp$1.parseExpressionStatement (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:966:10) at Parser.pp$1.parseStatement (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:730:24) at Parser.pp$1.parseBlock (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:981:25) at Parser.pp$1.parseStatement (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:709:33) at Parser.pp$1.parseTopLevel (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:638:25) at Parser.parse (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:516:17) at Object.parse (C:\Users\christian\AppData\Roaming\npm\node_modules\webpack\node_modules\acorn\dist\acorn.js:3098:39) @ ./~/graceful-fs/polyfills.js 2:16-36

package.json

{
  "name": "OrderEze.CRM",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "",
    "watch": "webpack-dev-server webpack.config.js --progress --colors --watch",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "OrderEze",
  "license": "ISC",
  "dependencies": {
    "babel-core": "6.7.4",
    "babel-loader": "6.2.4",
    "babel-preset-es2015": "6.6.0",
    "babel-preset-react": "6.5.0",
    "babel-preset-stage-1": "6.5.0",
    "classnames": "2.2.0",
    "css-loader": "0.19.0",
    "extract-text-webpack-plugin": "0.8.2",
    "react": "15.4.1",
    "react-dom": "15.4.1",
    "style-loader": "0.12.4",
    "webpack": "1.12.13"
  },
  "devDependencies": {
    "babel-eslint": "7.0.0",
    "eslint": "3.12.2",
    "eslint-config-airbnb": "12.0.0",
    "eslint-plugin-import": "1.16.0",
    "eslint-plugin-jsx-a11y": "2.2.2",
    "eslint-plugin-react": "6.3.0",
    "stylelint": "7.3.1"
  }
}

webpack.config.js

var aliases = require('./task-ticket/aliases.js');
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = {
  devtool: 'cheap-module-eval-source-map',
  entry: './task-ticket/index.jsx',
  output: {
    path: path.join(__dirname, '/build'),
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      exclude: /node_modules/,
      test: /\.jsx?$/,
      loader: 'babel-loader',
      query: {
        presets: ['es2015', 'react', 'stage-1']
      }
    },
    {
      test: /\.css?$/,
      loader: ExtractTextPlugin.extract('style-loader', 'css-loader')
    }]
  },
  plugins: [
    new ExtractTextPlugin('style.css')
  ],
  node: {
    fs: 'empty'
  },
  resolve: {
    root: path.resolve(__dirname),
    alias: aliases,
    extensions: ['', '.js', '.jsx', '.css']
  }
};

最佳答案

ERROR in (webpack)/~/constants-browserify/ constants.json [...]

您正在使用的某些模块需要一些 json 文件,因此您必须在 resolve.extensions 上允许 .json

resolve: {
  root: path.resolve(__dirname),
  alias: aliases,
  extensions: ['', '.js', '.jsx', '.css', '.json']
}

关于javascript - 使用 Extract Text Webpack 插件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41527542/

相关文章:

javascript - jQuery 用户界面 : Cannot drag a draggable element in z-axis stack

javascript - 如何使 iframe 响应

reactjs - 将 css 模块与 Extract Text 插件结合使用

编译后修改文件的webpack插件

java - Java与小程序之间的通信

javascript - Material Design Lite 的复选框不适用于列表

node.js - 在 webpack 构建期间登录到 Node 控制台或调试

reactjs - Webpack 自动要求所有文件中的一个文件...?

javascript - Gulp webpack-dev-server : callback before bundle is finished

css - 使用 ExtractTextPlugin 和 CommonsChunkPlugin 提取常用样式