Skip to content

Commit

Permalink
fix: experimentalUseImportModule
Browse files Browse the repository at this point in the history
use old publicPath logic
add CI tests for experimentalUseImportModule
disable auxiliaryAssets test with experimentalUseImportModule
  • Loading branch information
sokra committed Apr 14, 2021
1 parent e83bc84 commit e8934b8
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 44 deletions.
11 changes: 4 additions & 7 deletions .github/workflows/nodejs.yml
Expand Up @@ -50,22 +50,19 @@ jobs:
uses: wagoid/commitlint-github-action@v1

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

strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
node-version: [10.x, 12.x, 14.x]
webpack-version: [4, latest]
experimental-use-import-module: [false]
include:
- os: 'ubuntu-latest'
node-version: 14.x
webpack-version: latest
experimental-use-import-module: [false, true]
exclude:
- webpack-version: 4
experimental-use-import-module: true

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

steps:
- name: Setup Git
Expand Down
30 changes: 8 additions & 22 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -73,7 +73,7 @@
"npm-run-all": "^4.1.5",
"prettier": "^2.2.1",
"standard-version": "^9.1.0",
"webpack": "^5.32.0",
"webpack": "^5.33.2",
"webpack-cli": "^4.5.0",
"webpack-dev-server": "^3.7.2"
},
Expand Down
28 changes: 15 additions & 13 deletions src/loader.js
Expand Up @@ -174,6 +174,19 @@ export function pitch(request) {
return callback(null, resultSource);
};

const publicPath =
typeof options.publicPath === 'string'
? options.publicPath === 'auto'
? ''
: options.publicPath === '' || options.publicPath.endsWith('/')
? options.publicPath
: `${options.publicPath}/`
: typeof options.publicPath === 'function'
? options.publicPath(this.resourcePath, this.rootContext)
: this._compilation.outputOptions.publicPath === 'auto'
? ''
: this._compilation.outputOptions.publicPath;

if (optionsFromPlugin.experimentalUseImportModule) {
if (!this.importModule) {
callback(
Expand All @@ -183,11 +196,12 @@ export function pitch(request) {
);
return;
}
console.log(publicPath);
this.importModule(
`${this.resourcePath}.webpack[javascript/auto]!=!${request}`,
{
layer: options.layer,
publicPath: options.publicPath,
publicPath,
},
(err, exports) => {
if (err) {
Expand All @@ -206,18 +220,6 @@ export function pitch(request) {
this.addDependency(this.resourcePath);

const childFilename = '*';
const publicPath =
typeof options.publicPath === 'string'
? options.publicPath === 'auto'
? ''
: options.publicPath === '' || options.publicPath.endsWith('/')
? options.publicPath
: `${options.publicPath}/`
: typeof options.publicPath === 'function'
? options.publicPath(this.resourcePath, this.rootContext)
: this._compilation.outputOptions.publicPath === 'auto'
? ''
: this._compilation.outputOptions.publicPath;

const outputOptions = {
filename: childFilename,
Expand Down
3 changes: 2 additions & 1 deletion test/cases/auxiliaryAssets/test.filter.js
@@ -1,3 +1,4 @@
const webpack = require('webpack');

module.exports = () => webpack.version[0] !== '4';
module.exports = () =>
webpack.version[0] !== '4' && !process.env.EXPERIMENTAL_USE_IMPORT_MODULE;
6 changes: 6 additions & 0 deletions test/manual/webpack.config.js
Expand Up @@ -10,6 +10,11 @@ const ENABLE_ES_MODULE =
? Boolean(process.env.ES_MODULE)
: true;

const ENABLE_EXPERIMENTAL_USE_IMPORT_MODULE =
typeof process.env.EXPERIMENTAL_USE_IMPORT_MODULE !== 'undefined'
? Boolean(process.env.EXPERIMENTAL_USE_IMPORT_MODULE)
: true;

module.exports = {
mode: 'development',
output: {
Expand Down Expand Up @@ -58,6 +63,7 @@ module.exports = {
new Self({
filename: '[name].css',
chunkFilename: '[name].chunk.css',
experimentalUseImportModule: ENABLE_EXPERIMENTAL_USE_IMPORT_MODULE,
}),
],
devServer: {
Expand Down

0 comments on commit e8934b8

Please sign in to comment.