webpack无法加载模块jquery
我想使用webpack在打字稿中导入jquery。 这就是我所做的。
npm init -y npm install -g webpack npm install ts-loader --save touch webpack.config.js
在文件中,我写了这个
module.exports = { entry: './app.ts', output: { filename: 'bundle.js' }, resolve: { extensions: ['', '.webpack.js', '.web.js', '.ts', '.js'] }, module: { loaders: [ { test: /\.ts$/, loader: 'ts-loader' } ] } }
然后创buildapp.ts
并写下以下内容
import $ = require('jquery');
然后我npm install jquery --save
– 保存加载jquery组件。
那么当我执行webpack
它给我找不到模块的“jquery”消息。
ts-loader: Using typescript@1.6.2 Hash: af60501e920b87c93349 Version: webpack 1.12.2 Time: 1044ms Asset Size Chunks Chunk Names bundle.js 1.39 kB 0 [emitted] main + 1 hidden modules ERROR in ./app.ts (1,20): error TS2307: Cannot find module 'jquery'.
有人可以告诉我我做错了什么吗?
有人可以告诉我我做错了什么吗?
你需要jQuery的定义:
tsd install jquery --save
你也需要有一个tsconfig.json:
tsc -init
会为你生成一个。 但我build议:
{ "compilerOptions": { "module": "commonjs", "target": "es5" }, "exclude": [ "node_modules" ] }
你也需要安装打字稿
npm install typescript -save