You may need an appropriate loader to handle this file type.

    最近在構建一個typescript+react簡單項目的時候遇到了一個問題,運行webpack命令的時候報錯You may need an appropriate loader to handle this file type.可是我明明安裝了ts的loaderreact

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: [".ts", ".tsx", ".js", ".json"]
    },
    module: {
        rules: [
            // All files with a '.ts' or '.tsx' extension will be handled by 'awesome-typescript-loader'.
            { test: /\.tsx?$/, loader: "awesome-typescript-loader" },
            // { test: /\.tsx?$/, loader: "ts-loader" },
            // All output '.js' files will have any sourcemaps re-processed by 'source-map-loader'.
            { enforce: "pre", test: /\.js$/, loader: "source-map-loader" }
        ]
    },
    externals: {
        "react": "React",
        "react-dom": "ReactDOM"
    }
}

後來發現,當時項目搭建的時候官網讓我安裝webpack的時候我沒有安裝,用的全局webpack,項目中未安裝,因此我又安裝了webpack和webpack-cli,而後就解決了上述問題。webpack

相關文章
相關標籤/搜索