Skip to content

Commit e8934b8

Browse files
committed
fix: experimentalUseImportModule
use old publicPath logic add CI tests for experimentalUseImportModule disable auxiliaryAssets test with experimentalUseImportModule
1 parent e83bc84 commit e8934b8

File tree

6 files changed

+36
-44
lines changed

6 files changed

+36
-44
lines changed

.github/workflows/nodejs.yml

+4-7
Original file line numberDiff line numberDiff line change
@@ -50,22 +50,19 @@ jobs:
5050
uses: wagoid/commitlint-github-action@v1
5151

5252
test:
53-
name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }}
53+
name: Test - ${{ matrix.os }} - Node v${{ matrix.node-version }}, Webpack ${{ matrix.webpack-version }}, experimentalUseImportModule ${{ matrix.experimental-use-import-module }}
5454

5555
strategy:
5656
matrix:
5757
os: [ubuntu-latest, windows-latest, macos-latest]
5858
node-version: [10.x, 12.x, 14.x]
5959
webpack-version: [4, latest]
60-
experimental-use-import-module: [false]
61-
include:
62-
- os: 'ubuntu-latest'
63-
node-version: 14.x
64-
webpack-version: latest
60+
experimental-use-import-module: [false, true]
61+
exclude:
62+
- webpack-version: 4
6563
experimental-use-import-module: true
6664

6765
runs-on: ${{ matrix.os }}
68-
continue-on-error: ${{ matrix.experimental-use-import-module }}
6966

7067
steps:
7168
- name: Setup Git

package-lock.json

+8-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"npm-run-all": "^4.1.5",
7474
"prettier": "^2.2.1",
7575
"standard-version": "^9.1.0",
76-
"webpack": "^5.32.0",
76+
"webpack": "^5.33.2",
7777
"webpack-cli": "^4.5.0",
7878
"webpack-dev-server": "^3.7.2"
7979
},

src/loader.js

+15-13
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,19 @@ export function pitch(request) {
174174
return callback(null, resultSource);
175175
};
176176

177+
const publicPath =
178+
typeof options.publicPath === 'string'
179+
? options.publicPath === 'auto'
180+
? ''
181+
: options.publicPath === '' || options.publicPath.endsWith('/')
182+
? options.publicPath
183+
: `${options.publicPath}/`
184+
: typeof options.publicPath === 'function'
185+
? options.publicPath(this.resourcePath, this.rootContext)
186+
: this._compilation.outputOptions.publicPath === 'auto'
187+
? ''
188+
: this._compilation.outputOptions.publicPath;
189+
177190
if (optionsFromPlugin.experimentalUseImportModule) {
178191
if (!this.importModule) {
179192
callback(
@@ -183,11 +196,12 @@ export function pitch(request) {
183196
);
184197
return;
185198
}
199+
console.log(publicPath);
186200
this.importModule(
187201
`${this.resourcePath}.webpack[javascript/auto]!=!${request}`,
188202
{
189203
layer: options.layer,
190-
publicPath: options.publicPath,
204+
publicPath,
191205
},
192206
(err, exports) => {
193207
if (err) {
@@ -206,18 +220,6 @@ export function pitch(request) {
206220
this.addDependency(this.resourcePath);
207221

208222
const childFilename = '*';
209-
const publicPath =
210-
typeof options.publicPath === 'string'
211-
? options.publicPath === 'auto'
212-
? ''
213-
: options.publicPath === '' || options.publicPath.endsWith('/')
214-
? options.publicPath
215-
: `${options.publicPath}/`
216-
: typeof options.publicPath === 'function'
217-
? options.publicPath(this.resourcePath, this.rootContext)
218-
: this._compilation.outputOptions.publicPath === 'auto'
219-
? ''
220-
: this._compilation.outputOptions.publicPath;
221223

222224
const outputOptions = {
223225
filename: childFilename,
+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
const webpack = require('webpack');
22

3-
module.exports = () => webpack.version[0] !== '4';
3+
module.exports = () =>
4+
webpack.version[0] !== '4' && !process.env.EXPERIMENTAL_USE_IMPORT_MODULE;

test/manual/webpack.config.js

+6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ const ENABLE_ES_MODULE =
1010
? Boolean(process.env.ES_MODULE)
1111
: true;
1212

13+
const ENABLE_EXPERIMENTAL_USE_IMPORT_MODULE =
14+
typeof process.env.EXPERIMENTAL_USE_IMPORT_MODULE !== 'undefined'
15+
? Boolean(process.env.EXPERIMENTAL_USE_IMPORT_MODULE)
16+
: true;
17+
1318
module.exports = {
1419
mode: 'development',
1520
output: {
@@ -58,6 +63,7 @@ module.exports = {
5863
new Self({
5964
filename: '[name].css',
6065
chunkFilename: '[name].chunk.css',
66+
experimentalUseImportModule: ENABLE_EXPERIMENTAL_USE_IMPORT_MODULE,
6167
}),
6268
],
6369
devServer: {

0 commit comments

Comments
 (0)