我有一个npm脚本,是...
"theme: "cd node_modules/mylib && npm install && npm run build"
我的mylib
的npm脚本是...
"build": "webpack --config webpack.config.js"
一切正常,直到webpack部件抛出许多此类错误,这是一个...
ERROR in ./src/components/DataGrid/DataGridBody/DataGridBody.js
Module parse failed: Unexpected token (8:8)
You may need an appropriate loader to handle this file type.
|
| const DataGridBody = props => {
| return <tbody>{props.children}</tbody>;
| };
|
@ ./src/components/DataGrid/DataGridBody/index.js 1:0-41
@ ./src/components/DataGrid/index.js
@ ./src/components/index.js
但是,如果我在mylib
的仓库中运行该脚本,它将正常工作。
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: path.join(__dirname, 'src', 'components', 'index.js'),
output: {
libraryTarget: 'commonjs',
library: '',
path: path.resolve(__dirname, 'dist/themes'),
filename: '[name].css',
},
module: {
rules: [{
test: /\.jsx?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
plugins: [require('@babel/plugin-proposal-object-rest-spread')],
},
},
},
{
test: /\.s?css/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [{
loader: 'css-loader',
options: {
modules: true,
sourceMap: true,
importLoaders: 1,
localIdentName: '[local]',
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
ident: 'postcss',
plugins: loader => [require('autoprefixer')({
grid: true
})],
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
}),
},
],
},
plugins: [new ExtractTextPlugin({
filename: '[name].css'
})],
};
我尝试将require.resolve
添加到预设中,但仍然遇到相同的错误。我认为webpack无法解决加载程序和预设。我只想运行node_modules
文件夹中的webpack和配置,作为生成CSS的方法,以后可以复制。
有什么我想念的吗?