作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个简单的 js 文件,我正在尝试使用 webpack 4:
const CopyPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin');
//const ClosurePlugin = require('closure-webpack-plugin')
const path = require('path');
module.exports = env => {
console.log("Building with env", env)
const config = {
entry: {
index: './src/index.js',
"network-mapper": './src/network-mapper/network-mapper.js'
},
externals: {
'angular': 'angular',
'cytoscape': 'cytoscape'
},
output: {
filename: '[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'umd'
},
module: {
rules: [
{
test: /\.css$/,
use: ['style-loader', 'css-loader'],
},
{
test: /\.(html)$/,
use: {
loader: 'html-loader',
}
},
{
test: /\.js$/,
exclude: /node_modules/,
//loader: 'babel-loader'
}
]
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: __dirname + '/src/public/index.html',
filename: 'index.html',
inject: 'body'
}),
new CopyPlugin([
{from: __dirname + '/src/public'}
])
],
optimization: {
// We no not want to minimize our code.
minimize: false
}
};
config.mode = (env.development === 'false' ? 'production' : 'development')
if (env.development === 'false') {
// config.optimization = {
// concatenateModules: false,
// minimizer: [
// new ClosurePlugin({mode: 'AGGRESSIVE_BUNDLE'}, {
// // compiler flags here
// //
// // for debuging help, try these:
// //
// // formatting: 'PRETTY_PRINT'
// // debug: true,
// // renaming: false
// })
// ]
// }
}
return config;
}
import
就可以了和
export
声明使其成为纯 js 并将其包含在
<script>
中标签
import {cytoscape} from "cytoscape";
export function networkMap() {
// TODO
var createNetworkType = function (id, color, description) {
return {
"id": id,
"label": color.charAt(0).toUpperCase() + color.slice(1).toLowerCase(),
"description": description,
"className": color.toLowerCase()
}
...
<script>
中时我得到的标签:
TypeError: "Object(...) is not a function"
scope.cytoscape = Object(cytoscape__WEBPACK_IMPORTED_MODULE_0__["cytoscape"])({
container: scope.container,
elements: scope.elements,
style: scope.style,
layout: scope.layout
});
最佳答案
导出不应该是函数表达式。它应该是一个对象。
module.exports = {}
module.exports = () => {}
module.exports = function(env) {
return {};
}
关于javascript - webpack 4 类型错误 : "Object(...) is not a function",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55922150/
我是一名优秀的程序员,十分优秀!