Skip to content

Commit 11ba5dd

Browse files
author
Martynas Žilinskas
committed
Aded scss rule and htmlOptions for html webpack plugin.
1 parent 7493592 commit 11ba5dd

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/contracts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import { Options } from "html-webpack-template";
2+
13
export interface SimplrWebpackOptions {
24
devServerPort?: number;
35
emitHtml?: boolean;
6+
htmlOptions?: Options;
47
projectDirectory: string;
58
entryFile?: string;
69
outputDirectory?: string;

src/webpack-config.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { SimplrWebpackOptions } from "./contracts";
1313
export function generateWebpackConfig(opts: SimplrWebpackOptions): Configuration {
1414
const options: Required<SimplrWebpackOptions> = {
1515
...opts,
16+
htmlOptions: opts.htmlOptions || ({} as Options),
1617
devServerPort: opts.devServerPort || 3000,
1718
entryFile: opts.entryFile || "./src/index.ts",
1819
outputDirectory: opts.outputDirectory || "./wwwroot",
@@ -30,8 +31,7 @@ export function generateWebpackConfig(opts: SimplrWebpackOptions): Configuration
3031
path: fullOutputDirectoryLocation
3132
},
3233
resolve: {
33-
// Add `.ts` and `.tsx` as a resolvable extension.
34-
extensions: [".ts", ".tsx", ".js", ".json"]
34+
extensions: [".ts", ".tsx", ".js", ".json", ".scss"]
3535
},
3636
module: {
3737
rules: [
@@ -55,6 +55,19 @@ export function generateWebpackConfig(opts: SimplrWebpackOptions): Configuration
5555
}
5656
}
5757
]
58+
},
59+
{
60+
test: /\.scss$/,
61+
use: [
62+
// Creates style nodes from JS strings.
63+
"style-loader",
64+
// // Translates CSS into CommonJS.
65+
// "css-loader",
66+
// Autoprefixer
67+
"postcss-loader",
68+
// Compiles Sass to CSS.
69+
"sass-loader"
70+
]
5871
}
5972
]
6073
},
@@ -68,7 +81,6 @@ export function generateWebpackConfig(opts: SimplrWebpackOptions): Configuration
6881
inject: false,
6982
template: HtmlWebpackTemplate,
7083
appMountIds: ["root"],
71-
7284
links: [
7385
// {
7486
// rel: "stylesheet",
@@ -82,7 +94,8 @@ export function generateWebpackConfig(opts: SimplrWebpackOptions): Configuration
8294
name: "viewport",
8395
content: "width=device-width, initial-scale=1"
8496
}
85-
]
97+
],
98+
...options.htmlOptions
8699
} as Options)
87100
]),
88101
new ForkTsCheckerWebpackPlugin({

0 commit comments

Comments
 (0)