gpt4 book ai didi

Webpack 配置(静态文件)

转载 作者:行者123 更新时间:2023-12-04 21:38:14 34 4
gpt4 key购买 nike

我正在尝试配置项目的构建结构,并希望通过 webpack 来完成这一切。我的项目由 TypeScript(对于这个问题不重要)、原始 CSS、HTML 模板(角度)和一个 index.html 组成

该项目目前的结构是:

- app
-- components
--- foo
---- foo.html
---- foo.css
---- foo-ctrl.ts
---- foo-directive.ts
--- bar
---- bar.html
---- bar.css
---- bar-ctrl.ts
---- bar-directive.ts
-- index.html
-- site.css
- dist
- package.json
- webpack.config.js

所需的输出将是(在 dist 下)
- js
-- bundle.js // or some other name
- views
-- foo.html // or foo/foo.html
-- bar.html // or bar/bar.html
- styles
-- foo.css // or foo/foo.css
-- bar.css // or bar/bar.css
-- sites.css
- index.html

我试过使用 raw-loaderfile-loader移动 html 文件无济于事。

我对 webpack 如何捆绑 ts/js 文件感到满意,但无法弄清楚如何移动静态文件 (html/css)。以下是我迄今为止所拥有的。
// webpack.config.js
module.exports = {
entry: [
'./app/app.ts',
'./app/index.html',
'./app/foo/foo.html',
'./app/bar/bar.html'
],
output: {
path: './dist/',
filename: 'js/bundle.js'
},
resolve: {
extensions: ['', '.webpack.js', '.web.js', '.ts', '.js']
},
module: {
loaders: [
{ test: /\.ts$/, loader: 'ts-loader' },
{ test: /\index.html$/, loader: 'file-loader?name=[name].[ext]' },
{ test: /(?:[^index.html]*).html/, loader: 'file-loader?name=views/[name].[ext]' }
]
}
};

注意:我知道我对 webpack 不太了解,我希望采用的方法可能不是建议的路线,所以我愿意改造整个结构。

最佳答案

如果您有权访问 my egghead series ,建议你看requiring templates .

如果没有,请查看 this directive .不再需要 templateUrl ,只需要模板,它就会被内联为一个字符串。

关于Webpack 配置(静态文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33082150/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com