Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: respect webpack defaults by using fully initialized compiler object #405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ dist
tmp
npm-debug.log*
.package.json
.idea

# Lock files shouldn't be committed for libraries https://stackoverflow.com/a/40206145
yarn.lock
Expand Down
14 changes: 8 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@ AssetsWebpackPlugin.prototype = {
apply: function (compiler) {
const self = this

self.options.path = path.resolve(
self.options.useCompilerPath
? (compiler.options.output.path || '.')
: (self.options.path || '.')
)
self.writer = createQueuedWriter(createOutputWriter(self.options))
compiler.hooks.initialize.tap('AssetsWebpackPlugin', () => {
self.options.path = path.resolve(
self.options.useCompilerPath
? (compiler.options.output.path || '.')
: (self.options.path || '.')
)
self.writer = createQueuedWriter(createOutputWriter(self.options))
})

const emitPlugin = (compilation, callback) => {
const options = compiler.options
Expand Down
31 changes: 31 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,35 @@ describe('Plugin', function () {

expectOutput(args, done)
})

describe('test compatibility with webpack defaults', function () {
const DEFAULT_WEBPACK_OUTPUT_DIR = path.join(__dirname, '../dist')
const expectDistOutput = require('./utils/expectOutput')(DEFAULT_WEBPACK_OUTPUT_DIR)

beforeEach(function (done) {
rmRf(DEFAULT_WEBPACK_OUTPUT_DIR, done)
})

it('support useCompilerPath without setting output.path', function (done) {
const webpackConfig = {
entry: path.join(__dirname, 'fixtures/one.js'),
plugins: [new Plugin({
useCompilerPath: true
})]
}

const expected = {
main: {
js: 'auto/main.js'
}
}

const args = {
config: webpackConfig,
expected: expected
}

expectDistOutput(args, done)
})
})
})