我需要使用webpack从打字稿中导入原始数据。这是我的设置:
$ tree
.
+-- file.txt
+-- main.ts
+-- package.json
+-- tsconfig.json
+-- webpack.config.js
Run Code Online (Sandbox Code Playgroud)
file.txt
file-content
Run Code Online (Sandbox Code Playgroud)
main.js
import file from './file.txt';
console.log(file);
Run Code Online (Sandbox Code Playgroud)
package.json
{
"devDependencies": {
"raw-loader": "^0.5.1",
"ts-loader": "^3.1.1",
"typescript": "^2.6.1",
"webpack": "^3.8.1"
}
}
Run Code Online (Sandbox Code Playgroud)
tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"sourceMap": true,
"noImplicitAny": true,
"module": "commonjs",
"target": "es5",
"baseUrl": "app"
},
"exclude": [
"node_modules"
]
}
Run Code Online (Sandbox Code Playgroud)
webpack.config.js
const path = require('path');
const config = {
entry: './main.ts',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'app.js'
},
module: {
rules: …Run Code Online (Sandbox Code Playgroud)