你可能需要一个合适的加载器来加载这个文件到 windows 而 webpack 不在 linux 和 mac os
you may need an appropriate loader to load this file on windows with webpack not in linux and mac os
我正在尝试编写一个 webpack 文件,它将在支持 es6 的 reactjs 中创建一个项目。这是我的 webpack.config.js
webpackConfig = {
/*entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist/'),
filename: 'build.js'
},*/
entry: {
lite: "./lite.js", pro: "./pro.js",
},
output: { filename: "dist/[name].js" },
plugins: [
new webpack.optimize.CommonsChunkPlugin("dist/init.js"),
new WebpackNotifierPlugin({alwaysNotify: true, title: 'Webpack'})
],
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: __dirname + '/src',
loader: 'babel-loader',
query: {
presets: ['react','es2015']
}
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules')
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.less$/,
loader: "style!css!less"
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
// { test: /\.css$/, loader: "style-loader!css-loader" },
]
}
};
这是我的 .babelrc 文件
{
"presets" : ["es2015", "react"]
}
它 运行 在 mac os 和 linux 上,但是当我尝试在 windows 中 运行 时遇到问题。该错误的任何解释?真奇怪。
这里是错误
ERROR in ./src/lite.js
Module parse failed: C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plugins\cf7s kins-visual\src\lite.js Unexpected token (9:12)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (9:12)
at Parser.pp.raise (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plugins \cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
at Parser.pp.unexpected (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plug ins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10)
at Parser.pp.parseExprAtom (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content \plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1822:12)
at Parser.pp.parseExprSubscripts (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-c ontent\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:17 15:21)
at Parser.pp.parseMaybeUnary (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-conte nt\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1692:1 9)
at Parser.pp.parseExprOps (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\ plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1637:21)
at Parser.pp.parseMaybeConditional (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp -content\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js: 1620:21)
at Parser.pp.parseMaybeAssign (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-cont ent\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1597: 21)
at Parser.pp.parseParenAndDistinguishExpression (C:\xampp\htdocs\ONLINE\CF7\cf7vi sualPlugin\wp-content\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\d ist\acorn.js:1861:32)
at Parser.pp.parseExprAtom (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content \plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1796:19)
@ ./lite.js 2:0-24
尝试更改此行:
包括:__dirname + '/src',
对此:
排除:/node_modules/,
它通过改变
对我有用
include: __dirname + '/src',
至
include: path.join(__dirname, 'src')
我正在尝试编写一个 webpack 文件,它将在支持 es6 的 reactjs 中创建一个项目。这是我的 webpack.config.js
webpackConfig = {
/*entry: './index.js',
output: {
path: path.resolve(__dirname, 'dist/'),
filename: 'build.js'
},*/
entry: {
lite: "./lite.js", pro: "./pro.js",
},
output: { filename: "dist/[name].js" },
plugins: [
new webpack.optimize.CommonsChunkPlugin("dist/init.js"),
new WebpackNotifierPlugin({alwaysNotify: true, title: 'Webpack'})
],
module: {
loaders: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
include: __dirname + '/src',
loader: 'babel-loader',
query: {
presets: ['react','es2015']
}
},
{
test: /\.css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?modules')
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test: /\.less$/,
loader: "style!css!less"
},
{
test: /\.(jpe?g|png|gif|svg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
]
}
// { test: /\.css$/, loader: "style-loader!css-loader" },
]
}
};
这是我的 .babelrc 文件
{
"presets" : ["es2015", "react"]
}
它 运行 在 mac os 和 linux 上,但是当我尝试在 windows 中 运行 时遇到问题。该错误的任何解释?真奇怪。
这里是错误
ERROR in ./src/lite.js
Module parse failed: C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plugins\cf7s kins-visual\src\lite.js Unexpected token (9:12)
You may need an appropriate loader to handle this file type.
SyntaxError: Unexpected token (9:12)
at Parser.pp.raise (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plugins \cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:2221:15)
at Parser.pp.unexpected (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\plug ins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:603:10)
at Parser.pp.parseExprAtom (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content \plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1822:12)
at Parser.pp.parseExprSubscripts (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-c ontent\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:17 15:21)
at Parser.pp.parseMaybeUnary (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-conte nt\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1692:1 9)
at Parser.pp.parseExprOps (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content\ plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1637:21)
at Parser.pp.parseMaybeConditional (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp -content\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js: 1620:21)
at Parser.pp.parseMaybeAssign (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-cont ent\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1597: 21)
at Parser.pp.parseParenAndDistinguishExpression (C:\xampp\htdocs\ONLINE\CF7\cf7vi sualPlugin\wp-content\plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\d ist\acorn.js:1861:32)
at Parser.pp.parseExprAtom (C:\xampp\htdocs\ONLINE\CF7\cf7visualPlugin\wp-content \plugins\cf7skins-visual\node_modules\webpack\node_modules\acorn\dist\acorn.js:1796:19)
@ ./lite.js 2:0-24
尝试更改此行:
包括:__dirname + '/src',
对此:
排除:/node_modules/,
它通过改变
对我有用include: __dirname + '/src',
至
include: path.join(__dirname, 'src')