我对前端很新,我一直在努力学习webpack。我在使用Extract-Text-Webpack-Plugin时遇到了一些问题,我似乎无法弄明白。我很感激有关这个主题的任何帮助。此外,欢迎任何建议/提示!
>警告在./~/chokidar/lib/fsevents-handler.js中 找不到模块:错误:无法在C:\ Git \ JNJ.Web \ src \ JNJ.Web.UI \ client \ node_modules \ chokidar \ lib中解析模块'fsevents' @ ./~/chokidar/lib/fsevents-handler.js 7:17-36(webpack)/〜/ constants-browserify / constants.json中的错误 模块解析失败:C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ constants-browserify \ _concants.json意外的令牌(2:12) 您可能需要适当的加载程序来处理此文件类型。 SyntaxError:意外的令牌(2:12) 在Parser.pp $ 4.raise(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:2221:15) 在Parser.pp.unexpected(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:603:10) 在Parser.pp.semicolon(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:581:61) 在Parser.pp $ 1.parseExpressionStatement(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:966:10) 在Parser.pp $ 1.parseStatement(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:730:24) 在Parser.pp $ 1.parseBlock(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:981:25) 在Parser.pp $ 1.parseStatement(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:709:33) 在Parser.pp $ 1.parseTopLevel(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:638:25) 在Parser.parse(C:\ Users \ christian \ AppData \ Roaming \ npm \ node_modules \ webpack \ node_modules \ acorn \ dist \ acorn.js:516:17) 在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
{
"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"
}
}
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']
}
};
答案 0 :(得分:1)
(webpack)中的错误/〜/ constants-browserify / constants.json [...]
您使用的某些模块需要一些json文件,因此您必须在.json
上允许resolve.extensions
。
resolve: {
root: path.resolve(__dirname),
alias: aliases,
extensions: ['', '.js', '.jsx', '.css', '.json']
}