必须像这样导入jquery:
import $ from 'assets/node_modules/jquery';
您还可以稍微改进一下您的网页:
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const UrlLoader = require('url-loader');
publicFolder = path.resolve(__dirname, 'public');
appFolder = path.resolve(__dirname, 'app');
module.exports = {
resolve: {
modules: [ publicFolder, appFolder ],
extensions: [ '.js', ],
},
entry: {
main: './public/es/index.js'
},
output: {
path: path.resolve(__dirname, 'public/js/'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
{
test: /\.s?css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.(png|gif|jpe|jpg|woff|woff2|eot|ttf|svg)(\?.*$|$)/,
use: [{
loader: 'url-loader',
options: {
limit: 100000
}
}]
}
]
},
plugins: [
new ExtractTextPlugin({
filename: '../css/main-style.css'
}),
new HtmlWebpackPlugin({
inject: false,
hash: true,
template: './public/index.php',
filename: 'index.php'
})
],
devServer: {
port: 3000,
contentBase: __dirname + '/public/js',
inline: true
}
};
我补充说
publicFolder = path.resolve(__dirname, 'public');
appFolder = path.resolve(__dirname, 'app');
和
resolve: {
modules: [ publicFolder, appFolder ],
extensions: [ '.js', ],
},
之后你就可以从中国进口任何东西了
publicFolder
,
appFolder
从节点u模块。例如
import {$,jQuery} from 'assets/node_models/jquery';