5
使用webpack ^v2.2.1
,我想導入一個TypeScript模塊作爲文本,除了導入相同的模塊「正常」。我想我可能應該使用raw-loader。但它沒有解決。Webpack:導入TypeScript模塊都「正常」和原始字符串
一些示例代碼:
import DemoComponent from './demo'
import demoCode from 'raw-loader!./demo'
打字稿在我尖叫像
error TS2307: Cannot find module 'raw-loader!./demo'.
我使用ts-loader。
這裏是我的webpack.config.js
:
const { resolve } = require('path')
const fail = require('webpack-fail-plugin')
const config = {
entry: './docs/index.ts',
output: {
filename: 'bundle.js',
path: resolve(__dirname, 'docs-build')
},
resolve: {
extensions: [ '.ts', '.js' ]
},
devtool: 'inline-source-map',
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader'
},
{
test: /\.ts$/,
loader: 'ts-loader'
},
{
test: /\.scss$/,
use: [
'style-loader',
{
loader: 'css-loader',
options: {
sourceMap: true
}
},
'sass-loader'
]
}
]
},
plugins: [
fail
]
}
module.exports = config
相關http://stackoverflow.com/questions/33915930/using-file-loader-與-es6-modules-and-typescript-in-webpack – Doug