-
Notifications
You must be signed in to change notification settings - Fork 915
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
refactor!: replace module.exports with ES module export #1674
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a5f4d40
refactor!: replace module.exports with ES module export
haoqunjiang e247c97
fix: make VueLoaderPlugin type constructable
haoqunjiang 6c99ed7
refactor: `import * as webpack` -> `import webpack`
haoqunjiang 0e392aa
test: add very basic smoke test
haoqunjiang 6ab93cb
ci: add circleci config
haoqunjiang dda790d
style: adjust the export statement location
haoqunjiang 8379dd5
test: require from the `dist` folder instead of `src`
haoqunjiang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
version: 2 | ||
jobs: | ||
build: | ||
docker: | ||
- image: circleci/node:lts | ||
|
||
working_directory: ~/repo | ||
|
||
steps: | ||
- checkout | ||
|
||
- restore_cache: | ||
keys: | ||
- v1-dependencies-{{ checksum "yarn.lock" }} | ||
- v1-dependencies- # used if checksum fails | ||
|
||
- run: yarn install | ||
|
||
- save_cache: | ||
paths: | ||
- node_modules | ||
- ~/.cache/yarn | ||
key: v1-dependencies-{{ checksum "yarn.lock" }} | ||
|
||
- run: yarn lint | ||
- run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
const webpack = require('webpack') | ||
let VueLoaderPlugin = null | ||
import webpack from 'webpack' | ||
declare class VueLoaderPlugin implements webpack.Plugin { | ||
static NS: string | ||
apply(compiler: webpack.Compiler): void | ||
} | ||
|
||
let Plugin: typeof VueLoaderPlugin | ||
|
||
if (webpack.version && webpack.version[0] > 4) { | ||
if (webpack.version && webpack.version[0] > '4') { | ||
// webpack5 and upper | ||
VueLoaderPlugin = require('./pluginWebpack5') | ||
Plugin = require('./pluginWebpack5').default | ||
} else { | ||
// webpack4 and lower | ||
VueLoaderPlugin = require('./pluginWebpack4') | ||
Plugin = require('./pluginWebpack4').default | ||
} | ||
|
||
module.exports = VueLoaderPlugin | ||
export default Plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { bundle } from './utils' | ||
|
||
test('basic', async () => { | ||
await bundle({ entry: 'basic.vue' }) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<template> | ||
<h2 class="red">{{msg}}</h2> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
data () { | ||
return { | ||
msg: 'Hello from Component A!' | ||
} | ||
} | ||
} | ||
</script> | ||
|
||
<style> | ||
comp-a h2 { | ||
color: #f00; | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Component from '~target' | ||
import * as exports from '~target' | ||
|
||
if (typeof window !== 'undefined') { | ||
window.module = Component | ||
window.exports = exports | ||
} | ||
|
||
export default Component |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require
require('vue-loader').default
? Does webpack have built-in esModule default interop?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, webpack uses
loader-runner
to run loaders, and it supports.default
https://github.com/webpack/loader-runner/blob/master/lib/loadLoader.js#L26Or we can provide another
.cjs
entry if compatibility is a concern.But I don't think it's necessary, as
vue-loader
is only supposed to be called by webpack.