webpack 无法加载模块 jquery
webpack cannot load module 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' }
]
}
}
然后创建app.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'.
谁能告诉我我做错了什么?
Can somebody tell me what I did wrong?
您需要 jquery 定义:
tsd install jquery --save
你还需要 tsconfig.json:
tsc -init
将为您生成一个。但我推荐:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5"
},
"exclude": [
"node_modules"
]
}
还需要安装打字稿
npm install typescript -save
我正在尝试使用 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' }
]
}
}
然后创建app.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'.
谁能告诉我我做错了什么?
Can somebody tell me what I did wrong?
您需要 jquery 定义:
tsd install jquery --save
你还需要 tsconfig.json:
tsc -init
将为您生成一个。但我推荐:
{
"compilerOptions": {
"module": "commonjs",
"target": "es5"
},
"exclude": [
"node_modules"
]
}
还需要安装打字稿
npm install typescript -save