sli*_*wp2 6 ejs node.js express typescript webpack
我用express
+ webpack3
+ ejs
+typescript
当我构建时,stdout
输出会给我一些警告:
WARNING in ./node_modules/ejs/lib/ejs.js
require.extensions is not supported by webpack. Use a loader instead.
@ ./src/environment.ts 4:10-24
@ ./src/server.ts
WARNING in ./node_modules/ejs/lib/ejs.js
require.extensions is not supported by webpack. Use a loader instead.
@ ./src/environment.ts 4:10-24
@ ./src/server.ts
WARNING in ./node_modules/express/lib/view.js
80:29-41 Critical dependency: the request of a dependency is an expression
Run Code Online (Sandbox Code Playgroud)
这是一部分webpack.config.ts
:
import * as webpack from 'webpack';
import * as path from 'path';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
const config: webpack.Configuration = {
target: 'node',
devtool: 'source-map',
entry: {
server: path.resolve(__dirname, './src/server.ts')
},
output: {
path: path.resolve(__dirname, 'build'),
filename: 'server.js'
},
module: {
rules: [
{
test: /\.tsx?$/,
exclude: /node_modules/,
loader: 'ts-loader'
}
]
},
resolve: {
extensions: ['.ts', '.tsx', '.js']
},
plugins: [
new CopyWebpackPlugin([
{ from: './src/views', to: 'views' },
{ from: './src/public', to: 'public' }
])
]
};
export default config;
Run Code Online (Sandbox Code Playgroud)
和的一部分tsconfig.json
:
"include": [
"src/server.ts",
"src/typings"
],
"exclude": [
"node_modules",
"src/public",
"src/views"
]
Run Code Online (Sandbox Code Playgroud)
小智 5
我遇到了同样的问题,通过将以下代码添加到我的 webpack.config.js 文件中解决了它:
resolve: {
alias: {
'express-handlebars': 'handlebars/dist/handlebars.js'
}
}
Run Code Online (Sandbox Code Playgroud)
最好的解决方案是使用webpack-node-externals在使用 webpack 作为后端时完全不用担心 node_modules。
当与后端的 Webpack 捆绑时 - 您通常不希望捆绑其 node_modules 依赖项。该库创建了一个外部函数,在 Webpack 中捆绑时忽略 node_modules。
归档时间: |
|
查看次数: |
5120 次 |
最近记录: |