javascript Webpack:最小的TypeScript配置

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Webpack:最小的TypeScript配置相关的知识,希望对你有一定的参考价值。

const n_path = require('path')

//==============================================================================

const CONFIG = {
	root: {
		src:  n_path.resolve('./src'),
		dist: n_path.resolve('./dist'),
	},
	index:  'index.ts',
}

//==============================================================================

module.exports = {//============================================================

	entry:      n_path.join(CONFIG.root.src, CONFIG.index),

	output: {
		filename: 'bundle.js',
		path:     CONFIG.root.dist,
	},

	// Enable sourcemaps for debugging webpack's output.
	devtool: 'source-map',

	resolve: {
		// Add '.ts' and '.tsx' as resolvable extensions.
		extensions: [
			'.ts',
			'.tsx',
			'.js',
			'.json',
		],
	},

	module: {
		rules: [
			{// All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
				test:    /\.tsx?$/,
				exclude: /(node_modules)/,
				loader:  'awesome-typescript-loader',
			},
			{// All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
				enforce: 'pre',
				test:    /\.js$/,
				loader:  'source-map-loader'
			},
		],
	},

}//=============================================================================

以上是关于javascript Webpack:最小的TypeScript配置的主要内容,如果未能解决你的问题,请参考以下文章

webpack处理最小化JS文件

webpack处理最小化JS文件

pika开源:替代WebPack的全新JS构建工具

重温 Webpack, Babel 和 React

Webpack 4 - 如何配置最小化?

如何最小化 webpack 包的大小?