我有2个webpack项目:
“ c1”效果很好。
但是“ project-1”无效。
“ project-1”结构为:
|-节点模块
|-dist
|-src
| --- c1(符号链接 => c1 / src)
| ---主页
|-.babelrc
|-package.json
|-package-lock.json
|-webpack.config.js
.babelrc
{
"plugins": ["@babel/plugin-proposal-class-properties"]
}
webpack.config.js
const path = require('path')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const app = {
"folder": "home",
"entry": { "home" : "./src/home/Home.js" },
"template": "./src/home/index.ejs",
"fileNameCSS": "home.css"
}
module.exports = {
mode: 'development',
devtool: 'inline-source-map',
entry: app.entry,
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist') + '/' + app.folder,
},
resolve: {
alias: {
c1: path.resolve(__dirname, 'src/c1'),
}
},
module: {
rules: [
{
test: /\.(sa|sc|c)ss$/,
use: [
MiniCssExtractPlugin.loader,
{ loader: 'css-loader', options: { url: false, sourceMap: true } },
{ loader: 'sass-loader', options: { url: false, sourceMap: true } }
],
},
{
test: /\.ejs$/,
loader: 'ejs-loader?variable=data'
},
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: app.fileNameCSS ,
}),
new HtmlWebpackPlugin({
filename: 'index.html',
template: app.template
})
],
}
project-1 / src / home / Home.js
import Button from 'c1/button/Button'
export default class Home {...}
new Home()
在构建时,出现以下错误:
ERROR in g:/web/test/c1/src/button/Button.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: g:\web\test\c1\src\button\Button.js: Support for the experimental syntax 'classProperties' isn't currently enabled (3:8):
1 | export default class Button
2 | {
> 3 | el = null
| ^
4 | ...
5 | }
如何通过使用符号链接在没有复制/粘贴的情况下使用另一个项目中的“组件”。