typescript webpack工程步骤

typescript webpack工程步骤

前置条件:安装完nodejs,然后typescript,webpack全局安装

1.创建目录

2.npm init 生成 package.json

3.npm install --save 添加工程依赖

4.npm install --save-dev添加开发依赖,npm install --save-dev添加开发依赖,typescript工程一般需要添加npm install --save-dev typescript awesome-typescript-loader source-map-loader,其中:awesome-typescript-loader可以让Webpack使用TypeScript的标准配置文件tsconfig.json编译TypeScript代码。 source-map-loader使用TypeScript输出的sourcemap文件来告诉webpack何时生成自己的sourcemaps。 这就允许你在调试最终生成的文件时就好像在调试TypeScript源码一样。

5.tsc -init 生成tsconfig.json 文件,然后修改为类似如下

{"compilerOptions": {"outDir":"./dist/","sourceMap":true,"noImplicitAny":true,"module":"commonjs","target":"es5","jsx":"react"},"include": ["./**/*"],"exclude": ["node_modules"]

}

6.创建一个webpack配置文件webpack.config.js,类似如下:

module.exports = {

entry:"./src/index.tsx",

output: {

filename:"bundle.js",

path: __dirname +"/dist"},// Enable sourcemaps for debugging webpack's output.devtool:"source-map",

resolve: {// Add '.ts' and '.tsx' as resolvable extensions.extensions: ["",".webpack.js",".web.js",".ts",".tsx",".js"]

},module: {

loaders: [// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.{ test:/\.ts?$/, loader:"awesome-typescript-loader"}

],

preLoaders: [// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.{ test:/\.js$/, loader:"source-map-loader"}

]

},// When importing a module whose path matches one of the following, just// assume a corresponding global variable exists and use that instead.// This is important because it allows us to avoid bundling all of our// dependencies, which allows browsers to cache those libraries between builds.externals: {"react":"React","react-dom":"ReactDOM"},

};

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 无意中看到zhangwnag大佬分享的webpack教程感觉受益匪浅,特此分享以备自己日后查看,也希望更多的人看到...
    小小字符阅读 12,554评论 7 35
  • GitChat技术杂谈 前言 本文较长,为了节省你的阅读时间,在文前列写作思路如下: 什么是 webpack,它要...
    萧玄辞阅读 14,341评论 7 110
  • 学习流程 参考文档:入门Webpack,看这篇就够了Webpack for React 一. 简单使用webpac...
    Jason_Zeng阅读 8,356评论 2 16
  • 背景 很多很多传统的Web开发者还在用着传统的jquery和ES5,大家都知道现在的前端如火如荼,但是眼花缭乱的框...
    愤怒的摩托阅读 4,624评论 1 2
  • 最近,群里有老师问幼儿适合的教材,视频或者儿歌。让我不禁想起了自己教幼儿的时光。2013-2015,我在美国一所公...
    素秋微菊阅读 10,875评论 3 16

友情链接更多精彩内容