Skip to content

Commit 4463813

Browse files
committed
fix(webpack): fix css setup on resources
closes #18
1 parent 78770e2 commit 4463813

File tree

2 files changed

+79
-9
lines changed

2 files changed

+79
-9
lines changed

webpack/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"webpack-dev-server": "^3.0.0",
77
"html-webpack-plugin": "^3.0.0",
88
"webpack-bundle-analyzer": "^3.0.0",
9+
"url-loader": "^4.0.0",
10+
"file-loader": "^6.0.0",
911
// @if shadow-dom
1012
"to-string-loader": "^1.0.0",
1113
// @endif

webpack/webpack.config.js

Lines changed: 77 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ const WebpackShellPluginNext = require('webpack-shell-plugin-next')
66
// @endif
77

88
// @if !css-module
9-
const cssLoader = "css-loader";
9+
const cssLoader = 'css-loader';
1010
// @endif
1111
// @if css-module
1212
const cssLoader = {
13-
loader: "css-loader",
13+
loader: 'css-loader',
1414
options: {
1515
modules: true,
1616
// https://github.com/webpack-contrib/css-loader#importloaders
@@ -68,30 +68,98 @@ module.exports = function(env, { /* @if jasmine || tape || mocha*/runTest, /* @e
6868
},
6969
module: {
7070
rules: [
71+
{ test: /\.(png|gif|jpg|cur)$/i, loader: 'url-loader', options: { limit: 8192 } },
72+
{ test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff2' } },
73+
{ test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'url-loader', options: { limit: 10000, mimetype: 'application/font-woff' } },
74+
{ test: /\.(ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/i, loader: 'file-loader' },
75+
7176
// @if !shadow-dom
72-
{ test: /\./* @if css */css/* @endif *//* @if less */less/* @endif *//* @if sass */scss/* @endif */$/i, use: [ 'style-loader', cssLoader, postcssLoader/* @if less */, 'less-loader'/* @endif *//* @if sass */, sassLoader/* @endif */ ] },
77+
{ test: /\.css$/i, use: [ 'style-loader', cssLoader, postcssLoader ] },
78+
// @if less
79+
{ test: /\.less$/i, use: [ 'style-loader', cssLoader, postcssLoader, 'less-loader' ] },
80+
// @endif
81+
// @if sass
82+
{ test: /\.scss$/i, use: [ 'style-loader', cssLoader, postcssLoader, sassLoader ] },
83+
// @endif
7384
// @endif
85+
7486
// @if shadow-dom
7587
{
76-
test: /\./* @if css */css/* @endif *//* @if less */less/* @endif *//* @if sass */scss/* @endif */$/i,
88+
test: /\.css$/i,
89+
// For style loaded in src/main.js, it's not loaded by style-loader.
90+
// It's for shared styles for shadow-dom only.
91+
issuer: /\/src\/main\.(js|ts)$/,
92+
use: [ 'to-string-loader', cssLoader, postcssLoader ]
93+
},
94+
// @if less
95+
{
96+
test: /\.less$/i,
97+
// For style loaded in src/main.js, it's not loaded by style-loader.
98+
// It's for shared styles for shadow-dom only.
99+
issuer: /\/src\/main\.(js|ts)$/,
100+
use: [ 'to-string-loader', cssLoader, postcssLoader, 'less-loader' ]
101+
},
102+
// @endif
103+
// @if sass
104+
{
105+
test: /\.scss$/i,
77106
// For style loaded in src/main.js, it's not loaded by style-loader.
78107
// It's for shared styles for shadow-dom only.
79108
issuer: /\/src\/main\.(js|ts)$/,
80-
use: [ 'to-string-loader', cssLoader, postcssLoader/* @if less */, 'less-loader'/* @endif *//* @if sass */, sassLoader/* @endif */ ]
109+
use: [ 'to-string-loader', cssLoader, postcssLoader, sassLoader ]
81110
},
111+
// @endif
112+
82113
{
83-
test: /\./* @if css */css/* @endif *//* @if less */less/* @endif *//* @if sass */scss/* @endif */$/i,
114+
test: /\.css$/i,
84115
// For style loaded in other js/ts files, it's loaded by style-loader.
85116
// They are directly injected to HTML head.
86117
issuer: /(?<!\/src\/main)\.(js|ts)$/,
87-
use: [ 'style-loader', cssLoader, postcssLoader/* @if less */, 'less-loader'/* @endif *//* @if sass */, sassLoader/* @endif */ ]
118+
use: [ 'style-loader', cssLoader, postcssLoader ]
88119
},
120+
// @if less
89121
{
90-
test: /\./* @if css */css/* @endif *//* @if less */less/* @endif *//* @if sass */scss/* @endif */$/i,
122+
test: /\.less$/i,
123+
// For style loaded in other js/ts files, it's loaded by style-loader.
124+
// They are directly injected to HTML head.
125+
issuer: /(?<!\/src\/main)\.(js|ts)$/,
126+
use: [ 'style-loader', cssLoader, postcssLoader, 'less-loader' ]
127+
},
128+
// @endif
129+
// @if sass
130+
{
131+
test: /\.scss$/i,
132+
// For style loaded in other js/ts files, it's loaded by style-loader.
133+
// They are directly injected to HTML head.
134+
issuer: /(?<!\/src\/main)\.(js|ts)$/,
135+
use: [ 'style-loader', cssLoader, postcssLoader, sassLoader ]
136+
},
137+
// @endif
138+
139+
{
140+
test: /\.css$/i,
141+
// For style loaded in html files, Aurelia will handle it.
91142
issuer: /\.html$/,
92-
use: [ 'to-string-loader', cssLoader, postcssLoader/* @if less */, 'less-loader'/* @endif *//* @if sass */, sassLoader/* @endif */ ]
143+
use: [ 'to-string-loader', cssLoader, postcssLoader ]
144+
},
145+
// @if less
146+
{
147+
test: /\.less$/i,
148+
// For style loaded in html files, Aurelia will handle it.
149+
issuer: /\.html$/,
150+
use: [ 'to-string-loader', cssLoader, postcssLoader, 'less-loader' ]
93151
},
94152
// @endif
153+
// @if sass
154+
{
155+
test: /\.scss$/i,
156+
// For style loaded in html files, Aurelia will handle it.
157+
issuer: /\.html$/,
158+
use: [ 'to-string-loader', cssLoader, postcssLoader, sassLoader ]
159+
},
160+
// @endif
161+
// @endif
162+
95163
// @if babel
96164
{ test: /\.js$/i, use: ['babel-loader', '@aurelia/webpack-loader'], exclude: /node_modules/ },
97165
// @endif

0 commit comments

Comments
 (0)